Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're making a number of assumptions here, some of which are wrong. I'll try to point them out.</p> <p>Adding a RigidBody to a gameobject is the right idea, but it's the Collider component that determines the shape and size of the object's collision. Consider adding a BoxCollider, SphereCollider or CapsuleCollider to both.</p> <p>I assume you're having trouble getting the objects to actually collide, this may be the solution.</p> <p>Also,</p> <pre><code>void OnCollisionEnter(Collider rigidbody){ </code></pre> <p><ol> <li>The parameter you've named 'rigidbody' is not guaranteed to be a RigidBody component. According to <a href="http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html" rel="nofollow">documentation</a> </p> <blockquote> <p>The Collision class contains information about contact points, impact velocity etc.</li> <li>The proper syntax for <a href="http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html" rel="nofollow">OnCollisionEnter</a> has a Collision parameter, not a Collider.</li> </ol> To access the rigidbody on the Collider, you'd have to use getcomponent on the object found by the Collider and check if the RigidBody component exists. I'm not sure this is what you're after, but the misleading parameter name should be checked.</p> </blockquote> <p>Anyway you've got the right idea regarding comparing a Collider's gameobject by tag. All you need to do is enforce the tag on the object, either in the editor or through code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload