- Home /
Moving a object when player enters trigger and play a sound
Hello, what i want to do is have the Player enter a box collider that activates some object and then applies force to that objects rigidbody so that it moves abit and then stops, kinda like a ghost paranormal event. I also want a sound to be played on entering the box collider. I also dont want the object to teleport from a to b, i just want it to have some movement when i enter a trigger and then stop. What do i use lerp? or what ?
I will be doing this "paranormal event" many places so i need to be able to drag my object from scene into the inspector so i would need a variable in top of the script.
Please help :)
Answer by Waldy · Aug 09, 2014 at 08:39 PM
This is very basic stuff which can easily be found by a simple Google search. You would use "http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html" to know when he player has entered the collider. Then you could use "http://docs.unity3d.com/ScriptReference/Vector3-forward.html" to move the object forward. For the sound you could use
audio.Play();
or
audio.PlayOneShot();
Again look at the documentation first "http://docs.unity3d.com/ScriptReference/AudioSource.html" :D Next time you should either check the Unity Scripting documentation first or Google your question before asking question on Unity Answers. But now you know :D