The class inherits MonoBehaviour, and the script hangs on the scene object
private static ClassName mInstance;
public static ClassName GetInstance
{
get
{
return mInstance;
}
}
void Awake()
{
mInstance = this;
}
ps:无需通过该脚本挂载的物体来获取。
错误:GameObject.Find("脚本挂载物体名称").Getcomponent<ClassName>();
正确:ClassName.GetInstance.(public方法和字段)