- Home /
Script throwing error Operator '==' cannot be used with a left hand side of type System.Object and right hand side of type Controller
Hello - in my game the player can switch between the first person controller and the third person controller on pressing the space bar.
On hitting a collider however, after three seconds it is switched to the first person controller automatically (without the player pressing space)
I have one script which switches between the controllers, and one script which forces the player into first person.
The problem I'm having is I'm being thrown this errorBCE0051:Operator '==' cannot be used with a left hand side of type 'System.Object' and a right hand side of type 'Controller'
in reference to this line: if(other.tag == "Player" && SwitchCharactersScript.controllerType == ControllerType.ThirdPersonController)
This is the SwitchControllers script:
#pragma strict
var cam01 : GameObject; // first person camera
var cam02 : GameObject; // third person camera
var player01 : GameObject; //first person controller
var player02 : GameObject; //third person controller
public enum ControllerType
{
FirstPersonController , ThirdPersonController
}
var controllerType : ControllerType;
function Start()
{
cam02.active = false;
player02.active = false;
cam01.active = true;
player01.active = true;
controllerType = ControllerType.FirstPersonController;
}
function Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
ToggleCharacterControllerType();
}
}
public function ToggleCharacterControllerType()
{
if(controllerType == ControllerType.FirstPersonController)
{
player02.transform.position = player01.transform.position;
player02.transform.rotation = player01.transform.rotation;
cam01.active = false;
player01.active = false;
cam02.active = true;
player02.active = true;
controllerType = ControllerType.ThirdPersonController;
}
else
{
player01.transform.position = player02.transform.position;
player01.transform.rotation = player02.transform.rotation;
cam02.active = false;
player02.active = false;
cam01.active = true;
player01.active = true;
controllerType = ControllerType.FirstPersonController;
}
}
And this is the ForceIntoFirstPerson script (which is throwing the error):
var SwitchCharactersScript : SwitchCharacters;
function OnTriggerEnter(other : Collider)
{
if(other.tag == "Player" && SwitchCharactersScript.controllerType == ControllerType.ThirdPersonController)
{
yield WaitForSeconds(3.0);
SwitchCharactersScript.ToggleCharacterControllerType();
}
}
If anyone could help, it would be so much appreciated!
Thanks, Laurien
Answer by cj_coimbra · Aug 30, 2013 at 07:58 PM
I think it could help:
where you write ControllerType.ThirdPersonController you should write SwitchControllers.ControllerType.ThirdPersonController
Thanks - the error is solved now! :)
For some reason the player sinks straight through the terrain now - although you can switch between them using the space bar, they sink straight down.
I know it's not because I've set something up wrong because when using a simple switch script it worked fine.
You don't know why this is by any chance?
Your answer
Follow this Question
Related Questions
Toggle between first and third person - how do I toggle back? 1 Answer
How to smooth between values? 2 Answers
In Javascript, can I reverse a boolean as so: boolean = !boolean 1 Answer
Play animation with FPS controller? 2 Answers
[C#] custom class keys in a dictionary, overloading == etc. 2 Answers