Advertisement
LittleAngel

Reference Support

Apr 27th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. // Static Variable to hold the reference to this script
  2. private static MyScriptName myScriptName;
  3.  
  4. // Reference Support
  5. // A reference can be cached by declaring private MyScriptName myScriptName;
  6. // & in Start(): myScriptName = MyScriptName.Instance();
  7. // Once cached, requires function are simply: myScriptName.SomeFunction ();
  8. //
  9. // Alternatively, you may simply reference MyScriptName without cacheing
  10. // by using MyScriptName.Instance().SomeFunction;
  11.  
  12. public static MyScriptName Instance () {
  13. if (!myScriptName) {
  14. myScriptName = FindObjectOfType(typeof (MyScriptName)) as MyScriptName;
  15. if (!myScriptName)
  16. Debug.LogError ("There needs to be one active MyScriptName script on a GameObject in your scene.");
  17. }
  18.  
  19. return myScriptName;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement