Hi - I posed this question a little while back and got a few helpful responses, although I haven’t fully solved the problem I’m having.
I have multiple trigger colliders set up in my scene. When the player enters a trigger area, I’d like them to be able to press a button (Spacebar) and display a GUI, press Spacebar again to display 2nd GUI, again to display 3rd GUI, etc. These GUIs should display is a specific sequence. Essentially, I’m trying to mimic looking at pages of a book, in order, but without any sort of “page turning” animation.
I have developed a Javascript that is, for the most part, working. However, during gmaeplay, sometimes (but not all of the time) it will display the pages out of sequence. It’s also built with a lot of “if, else if” statements, which I know some people arent a big fan of. In some cases, there are many more GUIs to display (up to 16) so this gets a bit clunky.
If anyone has thoughts on how to make this code cleaner and a bit more foolproof, I’d love to hear them. Thanks for your advice!
#pragma strict
var Texture1 : GUITexture;
var Texture2 : GUITexture;
var Texture3 : GUITexture;
function OnTriggerStay()
{
if(Texture1.enabled == false && Texture2.enabled == false && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
{
Texture1.enabled = true;
Texture2.enabled = false;
Texture3.enabled = false;
}
else if(Texture1.enabled == true && Texture2.enabled == false && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
{
Texture1.enabled = false;
Texture2.enabled = true;
Texture3.enabled = false;
}
else if(Texture1.enabled == false && Texture2.enabled == true && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
{
Texture1.enabled = false;
Texture2.enabled = false;
Texture3.enabled = true;
}
else if(Texture1.enabled == false && Texture2.enabled == false && Texture3.enabled == true && Input.GetKeyDown( KeyCode.Space ))
{
Texture1.enabled = false;
Texture2.enabled = false;
Texture3.enabled = false;
}
}
function OnTriggerExit()
{
Texture1.enabled = false;
Texture2.enabled = false;
Texture3.enabled = false;
}