I've been going off of this thread to try and figure it out so far:
http://www.tasharen.com/forum/index.php?topic=458.0I've created what I understand is a "singleton" script that I want to attach to a game object in my scene so that I can turn panels on/off with SetActive, but at the moment I can't successfully attach it to an object because it doesn't derive from MonoBehaviour.
Here is my singleton script (i've been trying to stick with javascript since I've found it tricky to make c# and js talk to each other):
#pragma strict
class UIManagerClass
{
private static var Instance : UIManagerClass = null;
var panelState : boolean;
public static function GetInstance() : UIManagerClass
{
if(Instance == null)
Instance
= new UIManagerClass
();
return Instance;
}
private function UIManagerClass ()
{
Debug.Log(panelState);
if (!panelState)
Debug.Log("panel off");
}
}
The private function UIManagerClass() is where I believe I'd add the SetActive(true/false) code, I think?
And this is my OnClick function called from a button:
function OnClick()
{
var uiControl : UIManagerClass = UIManagerClass.GetInstance();
uiControl.panelState = false;
uiControl.GetInstance();
}
This doesn't show any errors at the moment, but from my understanding I won't be able to reference the panel objects until I can attach this script to a game object in the scene, and I'm not sure how to do that.
I've tried adding "extends MonoBehaviour" and it lets me attach the script to an object, but tells me I can't use "new" and can only use AddComponent(). However, I'm not sure how to go about this (whenever I try something I seem to get varying errors, so I'm sure I'm not using the right code protocol or something).
Any assistance anyone can offer is very much appreciated, and I apologise if my code and/or methods are awfully ugly; I've been trying to teach myself by scouring the net and frankensteining pieces of code together.