- Home /
How do I show GUI texture when I click an Object?
Hi I am creating a diary page system so when you click on a page, the gui shows up on your screen. How would I go about doing this. I would also like to know how to get rid of it by pressing a key. Here is the code I have now:
var diary : GUITexture;
function Start (){
diary.enabled=false;
}
function Update () {
if (Input.OnMouseUp){
if (diary.enabled){
diary.enabled = false;
}
else {
diary.enabled = true;
}
}
}
Answer by robertbu · Jun 08, 2013 at 02:17 PM
If you want to show the texture if the user clicks anywhere you can do:
#pragma strict
var diary : GUITexture;
function Start (){
diary.enabled=false;
}
function Update () {
if (Input.GetMouseButton(0)){
diary.enabled = true;
}
else {
diary.enabled = false;
}
}
To only show it if you click on a specific object, attach this to the object (which must have a collider):
#pragma strict
var diary : GUITexture;
function Start (){
diary.enabled=false;
}
function OnMouseDown() {
diary.enabled=true;
}
function OnMouseUp() {
diary.enabled=false;
}
Thank you @robertbu your answer is very useful to me, I used Code To only show it if I click on a specific object, but I need to do more 2 things. When I click the first mouse click show GUITexture and disable First Person movement until I click the second mouse click to hide GUITexture and enable First Person movement again. Sorry I'm not programmer and I'm new here ....
Answer by ChristianBlandford · Mar 09, 2014 at 03:39 PM
or, you could make it so the game is paused when you click on it, plus a paper pickup sound.
#pragma strict
private var pauseEnabled = false;
var sound : AudioClip;
var diary : GUITexture;
function Start (){
diary.enabled=false;
}
function OnMouseDown(){
if(pauseEnabled == true)
//unpause the game
pauseEnabled = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
if(pauseEnabled == false)
pauseEnabled = true;
AudioListener.volume = 1;
Time.timeScale = 0;
Screen.showCursor = true;
diary.enabled=true;
audio.Play();
}
function OnMouseUp(){
pauseEnabled = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
diary.enabled=false;
}