Same Game Object Turning scripts on and off??

Hey,

So I have a game object that will eventually have 10 different scripts on it. I only want one script to run at a time so I created an 11th script to switch these on and off. I have followed both other posts on the forum and the scripting reference. I can’t figure out what is wrong with my script! Please help.

#pragma strict

var RoundOneRevealA;
var PlayerNames;

function Start () {

	PlayerNames = GetComponent(PlayerNames);
	RoundOneRevealA = GetComponent(RoundOneRevealA);

} 

function Update () {


	if(PlayerNames.enabled == true){
		RoundOneRevealA.enabled = false;
	}
 
	else
 
	{
		PlayerNames.enabled = false;
		RoundOneRevealA.enabled = true;
 
	}




}

I think the problem may be that:

In your ‘else’ statement, you set PlayerNames.enabled to false… but the else statement is only called if PlayerNames.enabled is false. Because the first ‘if’ statement executes if it is true, the else means the second block of code is only executed if its false, and then you set it to false where it’s supposed to be false already.

I worded that pretty badly, but do you get the logical problem I’m trying to explain?

Unfortunately I don’t think that that is the problem. I am getting errors on lines 8 and 9 which makes me think that I am getting the component incorrectly.

It may not be your specific problem, but it definitely is a logic problem.

As for GetComponent, you probably need to do transform.GetComponent to specify that you’re getting the components of THIS transform, or the transform that script is attached to.

Maybe but I don’t think that a script is a transform component.

Ok I got it! The problem was that I was not assigning the variables a type and in Unity the file name is also the typename. So I just need to change the following:

var RoundOneRevealA : RoundOneRevealA;
var PlayerNames : PlayerNames ;

Yes, scripts are components.

PlayerNames = this.transform.GetComponent<PlayerNames>();
RoundOneRevealA = this.transform.GetComponent<RoundOneRevealA>();

This will give you the scripts that are attached to that game object. Mind you this is C#… I’m not sure about Javascript.