Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by laurienash · Aug 30, 2013 at 07:38 PM · controllerscriptingbasicsbooleanoperator

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image laurienash · Aug 30, 2013 at 08:14 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges