Convert a "States" variable to a String so it can be shown in UI
Hey guys, first time poster, so if there's anything else I can add to the topic to help things go smoothly, please let me know!
I'm working on a game that is essentially a multiple choice test, and each question is a new State. Each time I enter a new State I assign that state to a "CurrentState" variable, and I want to simply update some UI using that variable. (So if someone finds a bug, they can see what state it is in and report it easier)
I've been trying to find a way that I can convert the "currentState" into a string, but no luck so far. Thanks in advance guys!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class StateController : MonoBehaviour {
public enum States {S1A,S1B,S1C,S1D,S1E};
public States currentState;
Answer by Wyattagum · Jun 07, 2018 at 07:06 AM
I didn't test it yet cuz I was scrolling through my emails and saw this question so here ya go, hopefully, it works!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class StateController : MonoBehaviour {
public enum States {S1A,S1B,S1C,S1D,S1E};
public States currentState.ToString(); //simply add that to it, I do that in my scripts
Unfortunately, it was not that simple haha. I had hoped it was though. I tried adding .ToString in a few places around my script just to be sure, but I most cases I come out with an error.
error CS1503 Argument '#1' cannot convert 'method group' expression to type 'object'
I'm no expert yet, but I think this has to do with the fact that "States" comes from... UnityEngine.EventsSystem? and the ToString function is part of just "Unity Engine"?
Is the variable a Number or a Letter? Just asking
So from what I understand so far (I picked this project up as an internship so I'm learning someone elses code haha) the "State" is basically the same as the States in the Animator. So how in the animator you would have states for "walk" "jump" "run" etc, this game uses each question as its "States" and just progresses through them 1 by 1. Not sure if that makes much sense haha.
Your answer
Follow this Question
Related Questions
BCE0022: Cannot convert 'String' to 'int' 0 Answers
Why is my listdisplaying that an item was removed? 0 Answers
Convert a GUIText's number to an Integer value. 0 Answers
How to change between two images on button click 3 Answers
Don't know how to convert a string value to add into a int dictionnary. 1 Answer