i would like to do like…if the character has touch the certain object…it would appear a button or etc… i try to use the transform.position.x…but it never work…i’ll try to look at unity scripting…but still dont get how to use it…
1 Answer
1The best alternative is to use a trigger: create a simple object - a sphere or cube - and mark Is Trigger in the Inspector. Adjust its dimensions and position to cover the volume you want. When it’s ok, disable Mesh Renderer in the Inspector to make it invisible.
Add to this object a script like this:
var button: Transform; // drag the button you want to show/hide here
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){
// the character started touching the trigger: show the button;
button.renderer.enabled = true;
}
}
// if you want to hide the button when the player exits, add this code:
function OnTriggerExit(other: Collider){
if (other.tag == "Player"){
// the character left the trigger - hide the button;
button.renderer.enabled = false;
}
}
NOTE: You must tag your player as “Player” for this to work.