Unable to change the text

When I finished my story and ran my game, I found that the text would stay on “New text” or unchanged text. I have tried to brake the code down and this is what I have. I still have no idea why it wont change the text. The text in my unity is named “Text” and the script is place inside that said text. I also am see a print in the console if I insert the print function into “state_cell” yet I cant change the text. Thanks for the help ahead of time.

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class TextController : MonoBehaviour {

    public Text text;

    private enum States {cell}
    private States myState;

    // Start of game

    void Start() {
        myState = States.cell;
    }

    // Function caller

    void Update() {
        print(myState);
        if (myState == States.cell) {
            state_cell();
        }
    }

    void state_cell() {
        text.text = "Test";
    }
}

Click on your object that has this script on it in the hierarchy. Then in the inspector locate where it has the text slot. Then drag and drop your text object from the hierarchy into the slot in the inspector. That should be it, your code looks just fine.

Right on the dot, thanks man.

Your very welcome. I look forward to seeing the story you come up with. =D

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms