Script error

Help

I need to solve compiler error in the script, even though i followed everything .
Here is the screenshot.

1 Like

Hello @Sabeen_Moin, how are you?

Would you mind sending the code within TextController?

Best Regards,

I’am fine thank you. Yes it will be great .

So, can you send it? The script within textcontroller

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

public class TextController : MonoBehaviour {

public Text text; 

private enum States {Cell, Mirror, Sheets_0, Lock_0, cell_mirror, sheet_1, Lock_1, freedom}; 
private States myStates; 

// Use this for initialization
void Start () {
	myStates = States.Cell; 

}

// Update is called once per frame
void Update () {
	print (myStates); 
}

void start_cell () {
		text.text = "You're in a prison cell, and you want to escape, There are"+
			        "some dirty sheets on the bed, a mirror on the wall, and the door"+
				    "which is locked from the outside"+
				    "Press S view sheets, M to view mirror and L to view lock";
     if (Input.GetKeyDown (KeyCode.Space)) { 
     }
}

}

My apology for any mistake in this conversation of solving this issue. I’am new to this forum and not know well know how to use it.

Thank you

1 Like

No problem at all :joy: I didn’t meant to be rude or anything, sorry if it sounded like it.

This error usually happens when something has not been identified (which returns a null reference), did you dragged the Text component in the inspector to the script public text variable (inspector too)?

Not doing this is usually what causes this problem in this lesson, let me know if it solves your issue.

By the way, welcome to the community, feel free to ask anything that you need!
Best Regards,

1 Like

No it’s okey :slight_smile:️i said apology because i often writes incomplete sentences .

I followed everything as the course video has shown .

There is a part in the video that the teacher drag the Text component to the script inspector. Take a look at 8min and forward from this class, at 10:00/15:06 he does what I’m saying that if you didn’t do it, it would cause a similar problem.

1 Like

I did the same several times i reached upto full TextController script then 3 new errors came up

it is hard to know what is causing this error, can you take a screenshot of the inspector that have this script? I’ve just copied and pasted your code in a unity project and it runs just fine, must be something in the GameObject structure

1 Like

Are you ensuring that you have the script attached to the “Text” and not the canvas.
The error thats occuring is because it cannot find the gameobject thats referenced in the script at runtime.
This usually means the script isnt attached/attached to the wrong object or that the object (In this case “Text”) is not in the scene.
I have this project on my pc still (Yay for finding my old unity backup last week) and its how mine is set up.

Also check in the inspector to make sure that under the text controller script (Where you have it attached if correct it should be “Text” in the game scene), it has a Text gameobject assigned there too.

2 Likes

I’am still having errors even after following everything the same Updated Sat Jan 07 2017 18:07

Under the update method you have written myState where it should be myStates

3 Likes

Thank you, it solved

2 Likes

Privacy & Terms