Set variable as type "script"

Hi, I know how to set a variable type as “script” like -

var buttonsScript : Buttons;

But what I’d like to do is set them in Start() upon the true or false of a boolean.

So what I have in Start() is -

function Start(){
	buttons = GameObject.Find("GUI Buttons");
// Is the player playing Multiplayer ?
	if(globalVarsScript.multiplayer){
		buttonsScript = buttons.GetComponent(NetworkButtons);
	}else{
		buttonsScript = buttons.GetComponent(Buttons);
	}

And a part in one of my functions is -

buttonsScript.touchBegan = false;
buttonsScript.touchBegan = false;
buttonsScript.fireBegan = false;

But doing it this way I get the error - Cannot convert ‘NetworkButtons’ to ‘Buttons’. for the line -

buttonsScript = buttons.GetComponent(NetworkButtons);

Because I thought I could change the variable buttonScript in Start(), is there a way to set the variable buttonScript as type “script” without giving it the script name?

You can reference any script by declaring it as a Monobehaviour, but this is not what you need.

Here are 3 options :

1)Have your Buttons calss and NetworkButtons class both extend the same class, let’s say BaseButtons for example. This class could be abstract in C#, not sure if you can do that in JS.

  1. Have the NetworkButtons extending the Buttons class and overriding methods where appropriate.

  2. Have both Buttons and NetworkButtons classes implement an interface, IPressable for example.

It all depends on how different your buttons are. If they are the same buttons, and simply trigger different events, they probably don’t even need to be 2 different classes. In that case, simply use SendMessage to link button presses to method calls in other scripts : it’s quick and lazy, but perfectly fine for forwarding simple UI events IMO.