• 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 merlijndev · Jan 03, 2013 at 07:43 PM · bce0051

getting a error with a switch statement

i'm trying to make a switch statement but i'm getting 3 error lines on 1 line of code, the error's say "operator '==' cannot be used with a left hand side of type 'system.type' and a right hand side of type 'PlayerState'. (BCE0051)" i'm new to coding so i havent got a clue, any help would be much appriciated`

 enum PlayerState
 {
     schaaplinks = 0,
 
     schaaprechts = 1,
 
     schaaplinksspring = 2,
 
     schaaprechtsspring = 3,
 }
 
 var playerState = PlayerState.schaaplinks;    
 
 var lives     : int = 3;
 
 var key                      : int = 0;
 
 var coins : int = 0;
 
 var projectiellazer : GameObject;
 
 var projectielslotlinks : Transform;
 
 var projectielslotrechts  : Transform;
 
 var schaaplinks : Material;
 
 var schaaprechts  : Material;
 
 var veranderschaap : boolean = false;
 
 var kijktlinks : boolean = false;
 
 private var coinlive : int = 20;
 
 private var canshoot : boolean = false;
 
 function Update ()
 
 {}
 
 function Addkeys ( numkey : int )
 {
     key += numkey;
 }
 function Addcoins ( numcoins : int )
 {
     coins = coins + numcoins;    
 }
 function setPlayerState ()
 {
     var playerControls = GetComponent ( "playerControls" );
     var charController = GetComponent ( CharacterController );
     switch  ( PlayerState )
         {
         case PlayerState.schaaplinks :
             break;
         case PlayerState.shaaprechts :
             break;
         case PlayerState.schaaplinksspring :
             break;
         case PlayerState.schaaprechtsspring :
             break;
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Jan 03, 2013 at 07:46 PM

PlayerState (upper case 'P') is an enumerated type. The variable you want to use in your switch statement is playerState (lowercase 'p').

Comment
Add comment · Show 9 · 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 merlijndev · Jan 03, 2013 at 08:03 PM 0
Share

allright now i got rid of 2 of the errors but one still remains

avatar image Dave-Carlile · Jan 03, 2013 at 08:23 PM 0
Share

What error still exists, and where is it?

avatar image Dave-Carlile · Jan 03, 2013 at 08:24 PM 0
Share

I assume you have a closing } at the end of your switch statement.

 switch (playerState)
 {
 }  <-- this isn't in your code sample
avatar image merlijndev · Jan 03, 2013 at 08:25 PM 0
Share

"operator '==' cannot be used with a left hand side of type 'system.type' and a right hand side of type 'PlayerState'. (BCE0051)" that is the error and it is on "switch ( playerState )"

avatar image Dave-Carlile · Jan 03, 2013 at 08:29 PM 0
Share

Can you add a comment with your latest code? Just the switch statement. The entire statement if possible.

Show more comments
avatar image
0

Answer by Piflik · Jan 03, 2013 at 07:47 PM

You use the Enum Type as variable in the switch statement, instead of the variable of the type PlayerState.

 switch(playerState) {
     //....
 }

and not

 switch(PlayerState) {
     //....
 }

Also, please format your code properly on future posts. An unformatted script is nigh illegible.

Comment
Add comment · Show 2 · 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 merlijndev · Jan 03, 2013 at 08:10 PM 0
Share

thank you but onfortunaetly there is still one error left

avatar image merlijndev · Jan 03, 2013 at 08:10 PM 0
Share

oh and thanks for the tip

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Classes and type casting? 2 Answers

BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float' !!! 1 Answer

How to assign multiple EditorApplication.update delegates in JS? 2 Answers

BCE0051: Operator '<' cannot be used... ? 1 Answer

Add or substract two quaternions/rotations 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