Cannot convert 'boolean' to 'somevariable'.

So I’ve got a problem I’m getting this compiler error in unity saying “Cannot convert ‘boolean’ to ‘Player_Controller’.” and I don’t know why? I’m trying to create a toggle scripts script that accesses two java scripts in the same object that this script is attached to. One is called “Free_Look” and the other is called “Player_Controller”, both are java scripts so I don’t have to worry about calling a C# script. Script below. Sorry if the script sucks I’m not a good programmer just trying to learn problem by problem.

var toggle : boolean = false;
var script1 : Free_Look;
var script2 : Player_Controller;

function Start() {
     script2 = GetComponent(Player_Controller).enabled = true;
     rigidbody.useGravity = true;
     script1 = GetComponent(Free_Look).enabled = false;
     Time.timeScale = 1;
}

function Update() {
     if (Input.GetKeyDown("f")) {
          toggle = !toggle;

     if (toggle) {
          print("Toggled ON");
          script1 = GetComponent(Free_Look).enabled = true;
          script2 = GetComponent(Player_Controller).enabled = false;
          rigidbody.useGravity = false;
          Time.timeScale = 0.5;
     }


     else {
          print("Toggled OFF");
          script2 = GetComponent(Player_Controller).enabled = true;
          rigidbody.useGravity = true;
          Script1 = GetComponent(Free_Look).enabled = false;
          Time.timeScale = 1;

     }
} 
}

Yes, please indent the code – that would be helpful.

But if I’m not mistaken, the lines like this are incorrect:

script2 = GetComponent(Player_Controller).enabled = true;

If script2 is a variable holding the Player_Controller script, you should just be able to say script2.enabled = true; once the variable is set. So make two lines – first set the variable, then enable the script.

Since you didn’t post what line the error is on, I’ll assume it happens on a line like line 6:

script2 = GetComponent(Player_Controller).enabled = true;

In this line, you are assigning to both script2 and GetComponent(Player_Controller).enabled a value of true, which of type boolean.

However, if we expand the types of each element, we can see a problem:

Player_Controller = Component->boolean = boolean;

As you can see there is a problem with this: You are assigning a boolean type to a Player_Controller type variable. What you probably expect it to do is assign GetComponent to script2 and then enable it. Simply describing it is already a two step process and the same goes for the code. You cannot do this in one line.