【问题标题】:Why when Instantiate new GameObjects it's not adding tag to them? [duplicate]为什么在实例化新的游戏对象时没有向它们添加标签? [复制]
【发布时间】:2017-05-15 20:26:36
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour {

    public float spinSpeed = 2.0f;
    public int cloneTests;
    public GameObject prefab;

    private bool rotate = false;
    private bool exited = false;

    private void Start()
    {
        for (int i = 0; i < cloneTests; i++)
        {
            GameObject Test = Instantiate(prefab);
            Test.tag = "Testing";
        }
    }
}

克隆正在运行。

但它不会将标签添加到每个游戏对象。 我怎样才能把所有的克隆作为孩子放在另一个 GameObject 下?

【问题讨论】:

  • 这就是你让他们成为孩子的方式:Test.transform.parent = this.transform;它正在工作。但是向每个标签添加新标签是行不通的。所有 lcones 都未标记。

标签: c# unity3d unity5


【解决方案1】:

测试是否已经声明了标签?如果您在 Unity 脚本参考中查找它,您会发现:

“标签在使用前必须在标签管理器中声明”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多