Adding an additional Textbox to the same canvas

Hello everybody :slight_smile: ,

I finished my own Text Adventure and want to add a little extra-feature. My goal is to show on the top left hand corner of the screen in which “Location” the player finds himself in (e.g. see picture).

Picture:

I would like Textbox 2 to change whenever the player goes to the next state (e.g. House or Plane).

What I already tried was to create a second textbox and a second script that extends the script for the first textbox, so that I can say: if the player is in state “x” the textbox 2 should print “x” location’s name. Unfortunetaly, I could not figure out how to do so.
Is there any way to do so? :slight_smile:

Thanks a lot in advance!

Hi @Bryan_FP,

You don’t necessarily need the additional script, you could use your first TextController script and add another public field;

public Text location;

Then from the Hierarchy, drag the new Textbox object into the newly exposed Location field within the TextController script component.

Within your game logic, use;

location.text = "Cell";

…for example, to populate it based on the current State.

Hope this helps :slight_smile:

1 Like

Thank you very much! It did help :smiley:

1 Like

Great, do you have it working as intended now? :slight_smile:

Yes, it works perfectly! :slight_smile:

1 Like

I tried to do the same but it’s not working, when I put the location.text = "room"; my game does’t work

 void state_room(){
		location.text = "Room";
		text.text = "You are in your room, and you want to escape. There are " +
					"some dirty sheets on the bed, a window and two doors. " +
					"One is locked from outside and another is the bathroom.\n\n" +
					"Press S to view Sheets, W to view the Window, L to view the Lock and B to view the Bathroom";
		if (Input.GetKeyDown (KeyCode.S))			{myState = States.sheets_0;}
		else if (Input.GetKeyDown (KeyCode.L))		{myState = States.lock_0;}
		else if (Input.GetKeyDown (KeyCode.W))		{myState = States.window_0;}
		else if (Input.GetKeyDown (KeyCode.B))		{myState = States.bathroom_0;}
	}

that’s a part of my code.

Just add a screenshot if I did right on the unity

Thanks

1 Like

Hey Henrique,

I am still a beginner but let’s see whether I can you help you :).

Did you include at the beginning public Text location; ?

1 Like

Yes I did just like the public Text text;

1 Like

Try to drag and drop you Location Textbox in the Script of your first Textbox (see attached Screenshot).

2 Likes

Hi @Henrique_Pirani,

I’m pretty sure @Bryan_FP has given you the answer in his post, but thought I would share this User Guide with you for the future, as it will help make your posted code a lot easier to read. :slight_smile:

Hope this is of use.

2 Likes

It worked,
I did what you said, first I was trying dragging only the one text to location and the other one to text, now I did the way u did on the pic and worked.

Thank you

2 Likes

Great!

I am glad it helped!

2 Likes

Privacy & Terms