在Unity中的其他脚本中重新启动一个脚本

时间:2015-05-07 20:56:55

标签: c# unity3d

如何在其他脚本中重新启动一个脚本? 我试过这个,但它不起作用

Ball.Start();

1 个答案:

答案 0 :(得分:4)

从Unity手册:

Like the Awake function, Start is called exactly once in the lifetime of the script.

你可以做的是:

void Start()
{
   Init();
}

public void Init()
{
   // Some logic here
}

然后,您可以随时随地拨打Init()

如果您指的是完全重置MonoBehaviour,您可以删除/添加它:

Destroy(gameObject.GetComponent<MyMonoBehaviour>());
gameObject.AddComponent<MyMonoBehaviour>();
相关问题