Unity3D work log [script singleton]

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方法和字段)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325484091&siteId=291194637