Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by bh03ig · Mar 18, 2018 at 10:36 AM · enumreturn value

Can't return Enum state to script

Hi,

I am building a multi-class game and I have a small enum FSM. I decided to split the FSM into another "Players" script, while I have another script named "UI". "UI" accesses this Players script.

I've never attempted to return an Enum type, so i've never experienced an error like this before. The error I get is "UI.cs | A constant value is expected | Line 52". I don't understand why it would need to be constant. If I place the Enum in the UI.cs file, the problem goes away. I don't understand why it is any different from another script file.

Perculiarly, I don't get the error with the following code block commented out in Players.cs:

  */void Start ()
  {
      PlayersTurn = TurnStates.Player_1_Turn;
  }*/


Players.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Players : MonoBehaviour {
 
     public static Players Script;
 
     public enum TurnStates { Player_1_Turn, Player_2_Turn };
 
     #region PLAYER FSM
     TurnStates PlayersTurn;
     #endregion
 
    void Awake()
     {
         Script = this;
     }

     /*
     // Use this for initialization
     void Start ()
     {
         PlayersTurn = TurnStates.Player_1_Turn;
     }*/
     
     // Update is called once per frame
     void Update () {
         
     }
 
     public TurnStates getPlayerTurnState()
     {
         return PlayersTurn;
     }
 
     public void setPlayerTurnState(TurnStates State)
     {
         PlayersTurn = State;
     }
 
     public TurnStates getPossibleTurnState_P1()
     {
         return TurnStates.Player_1_Turn;
     }
 
     public TurnStates getPossibleTurnState_P2()
     {
         return TurnStates.Player_2_Turn;
     }
 }


UI.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class UI : MonoBehaviour {
 
     public static UI Script;
 
     #region UI
     // Used to Display Time Passed since Game session start
     public Text txtTimePlayed;
     string TimeText = "Session Time: ";
     int Time_Integer;           // Hold Time.time integer from float
 
     // Used to Display the amount of convoys in accordance with the Player FSM
     public Text txtYourConvoys;
     string YourConvoyText = "Your Convoys: ";
 
     // Used to Display the current Players Turn with various variables
     public Text txtPlayerTurn;
     string PlayerTurnString = "Current Turn: ";
     string Player1_Turn_Text = "Player 1";
     string Player2_Turn_Text = "Player 2";
     #endregion
 
     void Awake()
     {
         Script = this;
     }
 
     void Start ()
     {
 
     }
     
     void Update ()
     {
         
     }
 
     public void update_SessionTime()
     {
         Time_Integer = (int)Time.time;
         txtTimePlayed.text = TimeText + Time_Integer.ToString();
     }
 
     public void Update_Convoys_And_PlayerTurn()
     {
         switch (Players.Script.getPlayerTurnState())
         {
             case Players.Script.getPossibleTurnState_P1():
                 txtYourConvoys.text = YourConvoyText + Player_1_Convoys.ToString();
                 txtPlayerTurn.text = PlayerTurnString + Player1_Turn_Text;
                 break;
             case Players.Script.getPossibleTurnState_P2():
                 txtYourConvoys.text = YourConvoyText + Player_2_Convoys.ToString();
                 txtPlayerTurn.text = PlayerTurnString + Player2_Turn_Text;
                 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

0 Replies

· Add your reply
  • Sort: 

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

128 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 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 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 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 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 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 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

Enum filter for Item system 1 Answer

I have trouble understanding arrays and enums. When and how? 0 Answers

Manage lots of enum choices in inspector 1 Answer

How do I use a function’s return value as a parameter in another function? 1 Answer

Editor Script to add element to an enum 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