Why when Instantiate new GameObjects it's not adding tag to them? [duplicate]

南楼画角 提交于 2019-12-20 07:52:51

问题


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";
        }
    }
}

The cloning is working.

But it's not adding the tag to each GameObject. And how can i put all the clones as childs under another GameObject ?


回答1:


Is testing already a declared tag? If you look it up in the Unity Script Reference you will find:

"Tags must be declared in the tag manager before using them"



来源:https://stackoverflow.com/questions/43988243/why-when-instantiate-new-gameobjects-its-not-adding-tag-to-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!