Click on prefab to display msg

hii, i want to make prefab clickable and when i'll click on it it will give some msg should appeared on same screen. i hav tried to use 'GUItext',guitexture,3dtext but it directly display msg without any click. so how should i achieve it?

Let me know if my question is incomplete or not understood?

2 Answers

2

You could use OnMouseDown and then enable or disable GUItext ,guitexture, 3dtext etc.

you should have a boolean to know when user clicked on something. for example

var showMessage : boolean = false; //a public variable to show text or not
function OnMouseDown ()
{
//user clicked on the object
showMessage=true;
yield WaitForSeconds(3);
showMessage=false;
}
function OnGUI ()
{
//if showMessage = true then show the message
if(showMessage)
{
//show text message
}
}

it makes the variable true and after 3 seconds again turn it to false for the message to disappear. you can also enable/disable objects/renderers/3d text or any other component.

ok but if i need to display 3d text on it, what should i have to do?

–

you can put your text in text property of the text mesh when you want to show it and when you don't want to show anything (after waitforseconds) make the text property equal to "" then it will not show anything. also you can add/remove the TextMesh component form the object or create a prefab of text mesh and instantiate it when you want to show the message and destroy it after some seconds (don't use this approach in mobile platforms).

–

i applied text mesh to all that prefabs for which i need to display certain msg on click on them. but becauz of that they are showing in 'free aspect view' , and we want to display it when i'll click on particular prefab. r u having any reference example for such problem. becauz i'm new to these things.?

–