当我一次调用LikeFrame1(),LikeFrame2(),LikeFrame3()函数时(即,第一次单击调用该函数的按钮),随机标签分配给了实例化的游戏对象(标签即将到来)从我做相同事情的其他函数中分别为LikeFrame1(),LikeFrame2(),LikeFrame3()) 当我再次单击该按钮时,它将分配适当的标签。
我试图更改在函数中调用分配新标签的位置
这是带有我的函数的脚本,这些函数实例化Gameobject并分配标签:
public class InventoryCreateButton : MonoBehaviour
{
public Button Button;
public void AddItemz1()
{
Button go = Instantiate(Button, new Vector3(0, 0, 0),
Quaternion.identity) as Button;
Button.tag = "poop";
go.transform.parent =
GameObject.Find("ButtonListContent1").transform;
Debug.Log("AddItemz1");
}
public void AddItemz2()
{
Button go = Instantiate(Button, new Vector3(0, 0, 0),
Quaternion.identity) as Button;
Button.tag = "poop2";
go.transform.parent =
GameObject.Find("ButtonListContent1").transform;
Debug.Log("AddItemz2");
}
我从这个脚本中这样称呼他们:
public class ChooseFrame : MonoBehaviour
{
public GameObject currentInterObj = null;
public InteractionObject currentInterObjScript = null;
public Inventory inventory;
public InventoryCreateButton inventorycreateButton;
public InventoryButtonGetImage inventoryButtonGetImage;
public void LikeFrame1()
{
currentInterObj = frame1;
if (currentInterObj && _soundOn1)
{
inventorycreateButton.AddItemz1();
_soundOn1 = false;
Debug.Log(_soundOn1);
}
else
{
SoundOn1(); //method that can turn the sound on
_soundOn1 = true;
Debug.Log(_soundOn1);
}
}
// Update is called once per frame
void SoundOn1()
{
Destroy(GameObject.FindWithTag("poop"));
}
public void LikeFrame2()
{
currentInterObj = frame2;
if (currentInterObj && _soundOn2)
{
inventorycreateButton.AddItemz2();
_soundOn2 = false;
Debug.Log(_soundOn2);
}
else
{
SoundOn2(); //method that can turn the sound on
_soundOn2 = true;
Debug.Log(_soundOn2);
}
}
// Update is called once per frame
void SoundOn2()
{
Destroy(GameObject.FindWithTag("poop2"));
}
public void LikeFrame3()
{
currentInterObj = frame3;
if (currentInterObj && _soundOn3)
{
inventorycreateButton.AddItemz3();
_soundOn3 = false;
}
else
{
SoundOn3(); //method that can turn the sound on
_soundOn3 = true;
}
}
// Update is called once per frame
void SoundOn3()
{
Destroy(GameObject.FindWithTag("poop3"));
}
没有错误消息,我希望在第一次而不是第二次调用函数时将正确的标签分配给实例化的游戏对象。