Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Static Variable to hold the reference to this script
- private static MyScriptName myScriptName;
- // Reference Support
- // A reference can be cached by declaring private MyScriptName myScriptName;
- // & in Start(): myScriptName = MyScriptName.Instance();
- // Once cached, requires function are simply: myScriptName.SomeFunction ();
- //
- // Alternatively, you may simply reference MyScriptName without cacheing
- // by using MyScriptName.Instance().SomeFunction;
- public static MyScriptName Instance () {
- if (!myScriptName) {
- myScriptName = FindObjectOfType(typeof (MyScriptName)) as MyScriptName;
- if (!myScriptName)
- Debug.LogError ("There needs to be one active MyScriptName script on a GameObject in your scene.");
- }
- return myScriptName;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement