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 BrentReel · Jun 07, 2018 at 02:23 AM · uistringconvertstates

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;



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

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
Comment
Add comment · Show 6 · 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 BrentReel · Jun 07, 2018 at 02:17 PM 0
Share

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"?

avatar image Wyattagum BrentReel · Jun 07, 2018 at 04:15 PM 0
Share

oof :P, heh good luck!

avatar image Wyattagum BrentReel · Jun 07, 2018 at 04:16 PM 0
Share

Is the variable a Number or a Letter? Just asking

avatar image BrentReel Wyattagum · Jun 07, 2018 at 04:26 PM 0
Share

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.

Show more comments

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

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

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


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