Help with displaying and changing text in game.

Hey everyone. I’ve been making games for a while using other frameworks that were designed for non programmers. I’ve jumped head first into Unity and I’ve been watching tons of videos, reading the forum posts etc. and just learning as much as I can over the last 2 weeks. One of my main goals is learning how to program. I’m working on it as much as possible and making good progress. (Haven’t done any since BASIC and obviously, that was a while ago.)

I could really some help getting pointed in the right direction. There’s a few pretty basic concepts that I’m having trouble wrapping my head around.

So I’m basically making a simple game that uses text and pixel art.

What I’m struggling with is how to display my text and images on a plane and have them change when certain variables change.

The flow would be like this.

The player starts the game and selects a destination from the map. This changes the location variable to, let’s say, “X”.

When my location variable is “X”, my displayed text is “X” and my displayed image is “X”.

When the player clicks a different location on the map, we change the location variable to “Y”.

When location variable is “Y”, my displayed text is “Y” and my displayed image is “Y”.

Logically very simple stuff, but I’m struggling with the implementation in Unity.

So how do I display text in a plane (if that’s indeed what I would use) and have it change depending on the players location.
logic wise, if location=x, print “blah,blah,blah” and have it wrapped in the plane/box?

Sorry if that was too much info, or not enough. lol and thanks in advance. At this point, the text part is really what I most want to learn.

Well to display the texts images you’ll have use function OnGUI. You can use a trigger to mark location “X” and a boolean to check whether the player is in location “X”… Here’s a basic example :

var inLocationX : boolean = false;
var textureX : Texture;

function OnTriggerEnter(other : Collider){
if(other.gameObject.name == "LocationX"){
inLocationX = true;
}
}
function OnTriggerExit(other : Collider){
if(other.gameObject.name == "LocationX"){
inLocationX = false;
}
}

function OnGUI(){
if(inLocationX){
//Display a text at the top right of the screen
GUI.Label(Rect(Screen.width - 100, 0, 100,50),"You are in location X");

//Display textureX at the center of the screen
GUI.DrawTexture(Rect(Screen.width/2 - 50,Screen.height/2 - 50, 100,100),textureX);
}
}

OnGUI, I had a feeling that’s where I was heading. Thank you. Excuse me for my ignorance, but where would I apply this script? Maybe an empty object called “rules” or something? Thanks for the help!

You’ll have to attach it to your player for it to work. You can attach it to other GameObjects as well but you’ll have to tweak the script a little.