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 Infectedspleen · Jan 23, 2014 at 01:58 PM · errorcontrollercasejs to c#ouya

can someone look at my script

Hi all,

I have a menu script in js and I have converted it over to c# using this convertor because OUYA dev is in c# and to get the controller to work i have to do it this way.

Any hoo... the js script works perfectly but the c# version gives me six errors all pointing at the "case" section. Could any of you kind folk have a look and point me in the right direction to fixing it.

The error I get on all six accounts is: Assets/Scripts/Menu.cs(45,17): error CS0266: Cannot implicitly convert type int' to Menu.CurrentFocus'. An explicit conversion exists (are you missing a cast?)

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
 GUISkin guiSkin;
 AudioClip selectAudio;
 int state = 0;
 
 
 
 enum CurrentFocus {button1=1, button2=2, button3=3}
 private CurrentFocus currentFocus = CurrentFocus.button1;
 
 
 void  Update (){
     if (Input.GetKeyDown(KeyCode.Space) || OuyaInput.GetButtonDown(OuyaButton.O, OuyaPlayer.P01)) {
         if(state == 0)Application.LoadLevel("Level1"); 
          else if(state == 1)Application.LoadLevel("HowToPlay");
          else if(state == 2)Application.LoadLevel("Credits");
   
     }
     
     if ( (OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01)) || (OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01)) ) {
         audio.Play();
     }
     
     if (Input.GetKeyDown(KeyCode.DownArrow) || OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01)) {
         state++;
         if(state > 2) state = 2;
     }
  
     if (Input.GetKeyDown(KeyCode.UpArrow) || OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01)) {
         state--;
         if(state < 0) state = 0;
     }
 
     switch (currentFocus) {
         case 1:
             if (Input.GetKeyDown(KeyCode.DownArrow) || OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01)) {
                 currentFocus = 2;
             } else if (Input.GetKeyDown(KeyCode.UpArrow) || OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01)) {
                 currentFocus = 1;
             }
             break;
         case 2:
             if (Input.GetKeyDown(KeyCode.DownArrow) || OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01)) {
                 currentFocus = 3;
             } else if (Input.GetKeyDown(KeyCode.UpArrow) || OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01)) {
                 currentFocus = 1;
             }
             break;
         case 3:
             if (Input.GetKeyDown(KeyCode.DownArrow) || OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01)) {
                 currentFocus = 3;
             } else if (Input.GetKeyDown(KeyCode.UpArrow) || OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01)) {
                 currentFocus = 2;
             }
             break;
     }
 
 
 }
 
 void  OnGUI (){
     GUI.skin = guiSkin;
     
     GUI.SetNextControlName("1");
     GUI.Button( new Rect(625,490,300,100), "", "button1");
     GUI.SetNextControlName("2");
     GUI.Button( new Rect(625,575,300,100), "", "button2");
     GUI.SetNextControlName("3");
     GUI.Button( new Rect(625,660,300,100), "", "button3");
     
     
     switch (currentFocus) {
         case 1:
             GUI.FocusControl("1");
             break;
         case 2:
             GUI.FocusControl("2");
             break;
         case 3:
             GUI.FocusControl("3");
             break;
             
     }
     
 }
 }

Many Thanks in advance

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 KellyThomas · Jan 23, 2014 at 02:39 PM

This code is switching back and forth between enum and int types. I would recommend remaining consistent unless necessary.

The switch could work like this:

 //switch (currentFocus) {
 //   case 1:

 switch (currentFocus) {
     case CurrentFocus.button1:


I would also use the enum when assigning values to currentFocus:

 //currentFocus = 2;
 currentFocus = CurrentFocus.button2;

However the error is saying that a cast is available so I guess you could use this less clear alternative:

 currentFocus = (CurrentFocus)2;
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 Infectedspleen · Jan 23, 2014 at 03:02 PM 0
Share

Thank you very much. Works a treat. Have a top day.

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

19 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 avatar image

Related Questions

Character moving forwards before pressing anything 0 Answers

Script error CS0029: Cannot implicitly convert type `float' to `bool' 1 Answer

error CS0029: Cannot implicitly convert type `UnityEngine.CharacterController[]' to `UnityEngine.CharacterController' 1 Answer

I've got a coding problem please help 1 Answer

third person controller script has an error on line 193 (bitwise or) 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