GUI Show Image on sphere collider zone and Input Button.

Hello,

I’m working on a 3D FPS game. I’m just starting getting familiar with scripting and Unity engine.

For my first scene, i’m trying to make appear an Image when you press an input button ( Xbox 360 controller), who works only when you on sphere collider zone. Something like pressing the 17, 18 or 19 Mapped Button Number corresponding to ( B ), ( X ), ( Y ) on my OS X El capitan driver.

I want also to make 3 levels and wish this function stay valable when i’ll come back from other levels. Bellow this, there’s a screenshot of my sphere collider, and the image that i’m tryng to make appear.


I’ve tried this script to make appear the Image when the player trigger the collider without any input button, but it doesn’t work.

#pragma strict

private var guiShow : boolean = false;  

var riddle : Texture;

function OnTriggerStay (Col : Collider) 
{
	if (Col.tag == "Player")
	{
		guiShow = true;
	}

}

function OnTriggerExit (Col : Collider) 
{
	if(Col.tag == "Player")
	{
		guiShow = false;
	}

}

function onGUI ()
{
	if(guiShow == true)
	{
		GUI.DrawTexture (Rect (Screen.width / 4.5, Screen.height/ 4, 1024, 512), riddle);
	} 
}

I’m not yet familiar with scripting and the EventSytem and Standalone Input Module.

I guess it’s not complicated and i assume that the question is quite often asked, but somebody help ?

OK I haven’t used an xBox controller but the input commands should be fairly standard. This shows how to set one up.
I’d use OnTriggerEnter to set your bool and OnTriggerExit to unset.

Next ditch the old OnGUI, the 4.6 UI is so good to work with. Basically you want a world space canvas attached to that desk. You just disable it till the bool that you’re in the trigger is true and you press the xBox button. The trigger input in Update just checks if the bool is true and if the the canvas isn’t already displaying and then enable it.

This tutorial maps a world space to a character but you just need it over that desk.

You’re not really using the event system just to show the canvas but it is worth getting used to the newer UI as that event system is just so good.