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 Benifir · Sep 02, 2013 at 09:05 AM · c#errorenum

Cannot Implicitly convert to bool problem?

I'm working on the main menu for my new IOS game and have run into a snag. I'm getting the error message:

Assets/SpaceCombatRPG-IOS Framework/Scripts/Non-Completed/MainMenu.cs(42,22): error CS0029: Cannot implicitly convert type MainMenu.Page' to bool'

And yes, I do know what it means, but I cannot figure out the correct way to fix it. And I do not have any boolean variables which is the odd part. I'm guessing the problem seems to be with the way I am storing variables from my enumeration? Here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class MainMenu : MonoBehaviour {
     private enum Page {
         NewGame = 0,
         Resume = 1,
         LoadGame = 2,
         Options = 3,
         MoreGames = 4,
         GameGuide = 5,
         Addons = 6,
         GameCenter = 7,
         MainMenu = 8
     }
 
     private Page _currentPage;
 
     public Texture2D gameNameTexture;
     public Texture2D defaultButton;
     public Texture2D addonsButton;
     public Texture2D moreGamesButton;
     public Texture2D gameGuideButton;
     public Texture2D gameCenterButton;
     
 
     void Start() {
         _currentPage = Page.MainMenu;
     }
 
     void OnGUI() {
         if(_currentPage = Page.MainMenu)
             DisplayMainMenu();
         else if(_currentPage = Page.NewGame)
             DisplayNewGameMenu();
         else if(_currentPage = Page.Resume)
             DisplayResumeMenu();
         else if(_currentPage = Page.LoadGame)
             DisplayLoadGameMenu();
         else if(_currentPage = Page.Options)
             DisplayOptionsMenu();
         else if(_currentPage = Page.MoreGames)
             DisplayMoreGamesMenu();
         else if(_currentPage = Page.GameGuide)
             DispayGameGuideMenu();
         else if(_currentPage = Page.Addons)
             DisplayAddonsMenu();
         else if(_currentPage = Page.GameCenter)
             DisplayGameCenterMenu();
         else
             DisplayMainMenu();
     }
 
     public void DisplayMainMenu() {
         GUI.BeginGroup(new Rect(0,60,500,300));
         if(GUI.Button(new Rect((Screen.width / 2) - 100, 60, 200, 25), "New Game"))        //Change the page to NewGame menu
             _currentPage = Page.NewGame;
         if(GUI.Button(new Rect((Screen.width / 2) - 100, 90, 200, 25), "Resume"))        //Change the page to Resume menu
             _currentPage = Page.Resume;
         if(GUI.Button(new Rect((Screen.width / 2) - 100, 120, 200, 25), "Load Game"))        //Change the page to LoadGame menu
             _currentPage = Page.LoadGame;
         if(GUI.Button(new Rect((Screen.width / 2) - 100, 150, 200, 25), "Options"))        //Change the page to Options menu
             _currentPage = Page.Options;
 
         if(GUI.Button(new Rect((Screen.width / 2) - 250, 75, addonsButton.width, addonsButton.height), addonsButton))
             _currentPage = Page.Addons;
         if(GUI.Button(new Rect((Screen.width / 2) - 250, 135, moreGamesButton.width, moreGamesButton.height), moreGamesButton))
             _currentPage = Page.MoreGames;
         if(GUI.Button(new Rect((Screen.width / 2) + 250, 75, gameGuideButton.width, gameGuideButton.height), gameGuideButton))
             _currentPage = Page.GameGuide;
         if(GUI.Button(new Rect((Screen.width / 2) + 250, 135, gameCenterButton.width, gameCenterButton.height), gameCenterButton))
             _currentPage = Page.GameGuide;
 
         GUI.Label(new Rect((Screen.width / 2) - (gameNameTexture.width / 2), 10 - (gameNameTexture.height / 2), gameNameTexture.width, gameNameTexture.height), gameNameTexture);
         GUI.EndGroup();
     }
 
     void Update() {
         Debug.Log(_currentPage);
     }
 
 #region Functions not Templated
     public void DisplayLoadGameMenu() {
 
     }
 
     public void DisplayNewGameMenu() {
 
     }
 
     public void DisplayResumeMenu() {
 
     }
 
     public void DisplayOptionsMenu() {
 
     }
 
     public void DisplayMoreGamesMenu() {
 
     }
 
     public void DispayGameGuideMenu() {
 
     }
 
     public void DisplayAddonsMenu() {
 
     }
 
     public void DisplayGameCenterMenu() {
 
     }
 #endregion
 }
 
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
3
Best Answer

Answer by meat5000 · Sep 02, 2013 at 09:14 AM

use = to change a value. Use == to check a condition, like in an if statement.

The error means you are trying to put something thats not a bool in to a bool. It may happen if you check a variable for true or false thats not a bool. If you are trying to check if it exists use 'null'.

To be direct, change

  if(_currentPage = Page.MainMenu)
 DisplayMainMenu();

to

  if(_currentPage == Page.MainMenu)
 DisplayMainMenu();

and do the same for the rest of the if statements

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 Benifir · Sep 02, 2013 at 09:24 AM 0
Share

Thanks, that was really quick. I've never really thought about the = and == statement differences so I'll have to remember that.

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

17 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

Related Questions

C# Enum for Animation Issue 1 Answer

Multiple Cars not working 1 Answer

C# Edit enum values in inspector 1 Answer

Distribute terrain in zones 3 Answers

not all lines of code running c# 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