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 ObviouslyInsane · Jan 11, 2012 at 01:26 AM · error messageswitchstatement

Need a little help with a switch statement

Hi all, I am getting an error in the following script that says 'Operator == cannot be used with a left hand side of type 'System.Type' and a right hand side of type State'. The error occurs at the beginning of the switch statement.

Here is the script:

 import System.Collections.Generic;
 enum State{open, close, inbetween}
 var openSound : AudioClip;
 var closeSound : AudioClip;
 
 var parts : GameObject[];
 var defaultColors : Color[];
 var particleEffect : GameObject;
 var go : GameObject;
 var maxDistance : float;
 var player : GameObject;
 var mytransform : Transform;
 var inUse = false;
 var MyGUI;
 var used = false; //track if the chest has been used or not
 var x : int;
 
 var cnt : int;
 var glow : boolean;
 var state = State;
 
 var loot : List.<Item>;
 var ItemGenerator : ItemGenerator;
 //[RequireComponent(typeof(BoxCollider))]
 //[RequireComponent(typeof(AudioSource))]
 
 //public State state;
 function Start() {
 loot = new List.<Item>();
 mytransform = transform;
 state = Chest.State.close;
 
 particleEffect.active = false;
 
 defaultColors = new Color[parts.Length];
 
 if(parts.Length > 0)
 for(cnt = 0; cnt < defaultColors.Length; cnt++)
 defaultColors[cnt] = parts[cnt].renderer.material.GetColor("_Color");
 }
 
 function Update () {
 if(!inUse)
 return;
 
 if(player == null)
 return;
 
 if(Vector3.Distance(mytransform.position, player.transform.position) > maxDistance && !inUse)
 MyGUI.chest.ForceClose();
 //SendMessageUpwards("CloseChest");
 }
 
 function OnMouseEnter() {
 Debug.Log("Enter");
 HighLight();
 }
 
 function OnMouseExit() {
 HighLight();
 }
 
 function OnMouseUp() {
 go = GameObject.FindGameObjectWithTag("Player");
 if(go == null)
 return;
 
 if(Vector3.Distance(transform.position, go.transform.position) > maxDistance)
 return;
 }
 
 switch (state) {  <<ERROR OCCURS HERE
 case State.open:
     state = Chest.State.inbetween;
     //StartCoroutine("Close");
     ForceClose();
 break;
 
 case State.close:
     if(MyGUI.chest != null) {
     MyGUI.chest.ForceClose();
     }
     state = Chest.State.inbetween;
     StartCoroutine("Open");
 break;
 
 }
 //if(state == Chest.State.close)
 //Open();
 //else
 //Close();
 
 function Open() {
 MyGUI.chest = this;
 player = GameObject.FindGameObjectWithTag("Player");
 inUse = true;
 animation.Play("");
 particleEffect.active = true;
 AudioClip.Play("openSound");
 if(!used)
 PopulateChest();//5
 //yield return new WaitForSeconds(2);
 
 state = Chest.State.open;
 //SendMessageUpwards("PopulateChest", 5); //gameObject
 SendMessageUpwards("DisplayLoot"); //gameObject
 
 }
 
 function PopulateChest() {
 //chest = go;
 for(cnt = 0; cnt < x; cnt++) { //x
 loot.Add(ItemGenerator.CreateItem());
 //loot[cnt].Name = "I:" + Random.Range(0, 100);
 used = true;
 }
 
 }
 
 function Close() {
 player = null;
 inUse = false;
 //SendMessageUpwards.DONT_REQUIRE_LISTENER("PopulateChest", 5);
 
 animation.Play("");
 
 particleEffect.active = false;
 AudioClip.Play("closeSound");
 //yield return new WaitForSeconds(2);
 
 state = Chest.State.close;
 
 if(loot.Count == 0)
 Destroy(gameObject);
 }
 
 function ForceClose() {
 SendMessageUpwards("CloseChest");
 
 StopCoroutine("Open");
 StartCoroutine("Close");
 }
 
 function HighLight() {
 if(glow) {
 if(parts.Length > 0)
 for(cnt = 0; cnt < defaultColors.Length; cnt++)
 parts[cnt].renderer.material.SetColor("_Color", Color.yellow);
 }
 
 else {
 if(parts.Length > 0)
 for(cnt = 0; cnt < defaultColors.Length; cnt++)
 parts[cnt].renderer.material.SetColor("_Color", defaultColors[cnt]);
 }
 }

This is only the second time I have had to use a switch statement and I cannot figure out why its throwing me this error. Can someone take a quick look and see what I'm doing wrong? Thank you!

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
0
Best Answer

Answer by Eric5h5 · Jan 11, 2012 at 01:45 AM

You've defined "state" as a type, rather than saying what it is.

 var state = State.open;

Or:

 var state : State;
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 ObviouslyInsane · Jan 11, 2012 at 03:02 AM 0
Share

Ha, can't believe I missed that. Thank you Eric!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Yield statement is not working 1 Answer

Why does my Switch statement only go through one case correctly? 1 Answer

want to convert too many if statements into 1 switch case statement. error help. 2 Answers

How to use switch statement? 2 Answers

Anyone help with my switch statement? 0 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