- Home /
how to make object do something when touched?
im making my game and i need to make elevator,i had make the elevator ,but i wanna make he do something just when i touch it
Comment
Touching means something like mouse click on the elevator? If so, you can do this by: inside Update() function, capture the mouse click action by Input.touches, raycast from that touch position and see whether it can hit the elevator, remember you need to add collider to the elevator in order to let it to be hit by the raycast. If hit, then do something you want to do.
Answer by Sisso · Oct 11, 2012 at 11:15 AM
Probably what you need is a Trigger that activate when something get into it.
// to use this function you need to be a Collider component with "trigger" property enabled
function OnTriggerEnter (other : Collider) {
....
}
Take a look on these documentations and its references:
Your answer
![](https://koobas.hobune.stream/wayback/20220613082153im_/https://answers.unity.com/themes/thub/images/avi.jpg)