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 /
avatar image
0
Question by idohadar111 · Apr 07, 2017 at 11:17 PM · buttontextpublicvoidwhy

why is my text not changing? [please help]

When I start my game I press a button that suppose to change the text to somthing but its not changing Why? Lines: 75-76

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class TCMain : MonoBehaviour {
     
     public Text text;
     public Text TB1;
     public Text TB2;
     public Text TB3;
     public Image imageGO;
     float timeLeft = 15f;
 
     public enum States {backstory, cell_1, scout_1, scout_2, talk_1, sleep_1, lock_1, blood_1, talk_2};
     public States myState;
     
     void Start () {
         myState = States.backstory;
     }
     
     public void Update () {    
     if (myState == States.backstory) {
             timeLeft -= Time.deltaTime;
           if(timeLeft < 0) {
         myState = States.cell_1;
         timeLeft=4f;
     }
             state_backstory();    
     }else if (myState == States.cell_1) {
         state_cell_1();
     }else if (myState == States.sleep_1) {
         state_sleep_1();
     }else if (myState == States.talk_1) {
         timeLeft -= Time.deltaTime;
           if(timeLeft < 0) {
         myState = States.talk_2;
     }
         state_talk_1();
     }else if (myState == States.scout_1) {
         timeLeft -= Time.deltaTime;
           if(timeLeft < 0) {
         myState = States.scout_2;
     }    
         state_scout_1();
     }else if (myState == States.scout_2) {
         state_scout_2();
     }else if (myState == States.lock_1) {
         state_lock_1();
     }else if (myState == States.blood_1) {
         state_blood_1();
     }else if (myState == States.talk_2) {
         state_talk_2();
     }
  }
   
      void state_backstory () {
         text.text="You wake up in an odd bed, you quickly realize that you are in a prison cell." +
                   "You try to remember what you did that caused your arrest. But you could not recall a thing." +
                   "You try to remember who you even are, but you couldn’t, no matter how hard you tried.";
         }
     
      void state_cell_1 () {
         text.text="You hear people whom you assume are guards outside the room. what will you do?";
         TB1.text="Go to sleep, maybe you just need a rest and you’ll remember?";
         TB2.text="Ask the guards why you’re there";
         TB3.text="Scout the room maybe you could find some clues?";          
     }
 
     public void state_pass () {
         state_sleep_1();
     }
     
      void state_sleep_1 () {
         TB1.text="";
         text.text="A day passes...";
         Day_2();
     }
     
     public void state_talk_1 () {
         text.text="You ask the guards why you’re there.\n" +
                   "They laugh at you… it seems this isn’t going anywhere.\n";
     }
     
     void state_talk_2 () {
         text.text="The guards leave, now that you’re on your own, what should you do?\n\n" +
                   "V.Scout the room, if the guards won’t give you answers you’ll get ‘em yourself!\n" +
                   "L.Try and pick the lock";
         
         if (Input.GetKeyDown(KeyCode.V)) {
             myState = States.scout_1;
         }else if (Input.GetKeyDown(KeyCode.L)) {
             myState = States.lock_1;
         }
     }
     
     public void state_scout_1 () {
         text.text="You look around the room…\n";
     }
     
     void state_scout_2 () {
         text.text="You look around the room…\nYou see some writing on the wall:”it never ends” and some scratches counting up to 20.";
         
         if (Input.GetKeyDown(KeyCode.V)) {
             myState = States.blood_1;
         }else if (Input.GetKeyDown(KeyCode.S)) {
             myState = States.scout_1;
         }
     }
     
     void state_lock_1 () {
         SceneManager.LoadScene("Lock");
                   
     }
     
     void state_blood_1 () {
         text.text="111";
     }
     
     
      void Day_2() {
         imageGO.sprite = Resources.Load<Sprite>("DayCounter2");
     }
 }


Comment
Add comment · Show 5
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 hexagonius · Apr 08, 2017 at 04:07 PM 0
Share

Do you reach the code that sets the text (is the method executed?) Does the console show any errors the moment that happens?
Have you tried backtracking the method to where it can possibly be called and see if code reaches there?

avatar image mnarimani · Apr 08, 2017 at 05:25 PM 0
Share

Where do you call state_pass function?

avatar image JustinEllis · Apr 08, 2017 at 05:26 PM 0
Share

What function does your button call?

avatar image idohadar111 · Apr 08, 2017 at 10:47 PM 0
Share

Yes no erroes everythings seems to be normal even the method executed

avatar image JustinEllis · Apr 09, 2017 at 03:51 PM 0
Share

If the method is being executed check that your text ui is set properly or if its active in the scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by JustinEllis · Apr 08, 2017 at 04:28 PM

Try checking if your enum is setting itself to the correct state or if any of the other states are are being called. You should use a series of debug.Logs so you can tell where things are not being called and where things are.

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lags, when i clicked several time on button 1 Answer

Write in button 2 Answers

Changing Text Based off of a Prefab 0 Answers

Clickable link with text 0 Answers

How to replace Button Text when clicking another button? 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