- Home /
Question is off-topic or not relevant : UA is for Specific Technical Questions, not for asking for scripts.
Display Press E to Pickup when mouse over object
I've trying to get this to work for a while.... When i look at an object i want the words Press E to pickup to be displayed..only when im near the object and looking at it? Help please
Do your research better, I Google using the following: "answers.unity3d.com display gui when mouse over"
Duplicated question:
http://answers.unity3d.com/questions/403683/display-guitexture-when-mouse-over-object.html
Answer by HuskyPanda213 · Apr 06, 2013 at 01:48 AM
What you could do is either a OnMouseOver(){} void or function and the script must be added to the pickup object. Or you could use vector3.distance to make it that you pick it up when your near(Note: this will not use direction so you can pick it up without looking at it). I would go to the unity3d script reference and look up these two things, but they will not be great but its pretty hard to make it work perfectly.
Answer by DryTear · Apr 06, 2013 at 01:29 AM
var Highlighted : boolean;
var ChosenColour : Color;
var PickUp : String = "This Cool Thing Im Looking At";
function OnMouseOver(){
transform.renderer.material.color = ChosenColour;
Highlighted = true;
}
function OnMouseExit(){
transform.renderer.material.color = Color.white;
Highlighted = false;
}
function OnGUI(){
if(Highlighted == true){
GUI.Label(Rect(Screen.width/2,Screen.height/2,200,20),"Press E to Pick up "+PickUp);
}
}
error - BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(String)' was found.