My player character can click on a object and choose what actions to do with it (LookAt, Open, etc).
If those actions are not possible he will reply with a line of text like:
“I cant get there”
“It’s empty.”
etc…
So far I’ve been doing a .js file and adding static variables there like:
static var cannotReachObject = "'I can't get there.'";
But I would like to do something more clean. I know there are lists and arrays and some people even have just tons of lines inside a .txt file. I’m not fully sure how to achieve that but what I was imagining is having a function with all the thoughts that could be loaded for the different actions, something like this:
function PlayerSays (text : String){
var cannotReachObject = "'I can't get there.'";
var emptyContainer = "'It's empty.'";
// enable the text GUI, say the selected line, leave it for 3 secs and then turn it off
showThoughts = true;
text //
yield WaitForSeconds (3);
showThoughts = false;
}
And ideally I would just have to write for the action:
function PlayerSays (cannotReachObject);
I’m just learning Unity so my knowledge on how to achieve this is very limited… I understand the concept of what I’m trying to do but i can’t figure out how to actually write it.
Any help very appreciated!
– UPDATE –
This is what I kind of have. Currently doesn’t work and just feels redundant:
var customSkin : GUISkin;
var showThoughts = false ;
var thoughts : String;
function OnGUI () {
GUI.skin = customSkin;
GUI.depth = 1;
if (showThoughts == true){
GUI.Label (Rect ((Screen.width * 0.5) - 500, (Screen.height - Screen.height * 0.2) + 40, 1000, 40), thoughts , GUI.skin.customStyles[1]);
}
}
function PlayerSays (text : String){
if(text == "cannotReachObject"){
thoughts = "'I can't get there.'";
}
if(text == "emptyContainer"){
thoughts = "'It's empty.'";
}
showThoughts = true;
yield WaitForSeconds (1);
showThoughts = false;
}