|
Hi, Im trying to make my player destroy a box when collides with it. Here's what I have so far: using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { private GameObject objPlayer; private GameObject objBox;
What do i need to put in the if statement to make my Player destroy the Box. I would appreciate any help you can give me as i have no idea what i am doing. Thanks in advance!
(comments are locked)
|
|
I think you'll want to restructure you code a little to use colliders. See these links for starters: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html http://answers.unity3d.com/questions/4063/ontriggerenter-question And what skovacs1 said. Having added the collider, you can use the OnTriggerEnter event (rather than Update event)
(comments are locked)
|

Did you even search? There's like a 100 posts about destroying stuff. http://answers.unity3d.com/search?q=destroy. Use Destroy(). If you want collision there are also like a 100 posts about collision. http://answers.unity3d.com/questions/tagged/collision. You need to set up colliders on your objects and you can use the physics, meaning you may need rigid bodies, or triggers (read the manual). With colliders, you can either raycast on your own or implement the built-in OnCollisionEnter or OnTriggerEnter methods.