I have this script, where when attached to an object, when you go near it, it opens a GUI menu, how do I change this script so that I can select the object to GetComponent for the GUI menu.
Heres the script :
var target : Transform;
function Update () {
var other = gameObject.GetComponent(“GUIStyleScript”);
if ( Vector3.Distance(target.position, transform.position ) < 10) {
other.enabled = true;
}
if ( Vector3.Distance(target.position, transform.position ) > 10) {
other.enabled = false;
}
}
This part of the question doesn’t seem clear to me. Can you reword it?
Ok, How do I change it so the GUI menu opens (gameObject.GetComponent(“GUIStyleScript”); ) when I click the object rather than when I go near it.
I’m afraid I don’t know what you mean by ‘GUI menu opens gameObject.GetComponent(“GUIStyleScript”)’. But as for detecting when an object has been clicked, if it has a collider associated with it, you can use Physics.Raycast() or the OnMouseDown() callback.
ah ok the gameObject.GetComponent(“GUIStyleScript”); was referring to the script up top but the OnMouseDown isnt recognised by the console ill try a Raycast now