- Home /
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");
}
}
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?
Yes no erroes everythings seems to be normal even the method executed
If the method is being executed check that your text ui is set properly or if its active in the scene.
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612114927im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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