- Both of the items should have Collider Component;
- The relative moving object need to add rigid body.
Step 3: Write code to control the effect of collision and drag it on Rock
Note: OnTriggerEnter() is a function that can detect the collision. It also can get which object conflicts the object. So, the collider must check the Trigger attribute and set its unique tag.
Step 4: Run the game
Another way to detect collision: Do not check Trigger attributes and use OnCollisionEnter() function.
function OnCollisionEnter(collision:Collision){
if(collision.gameObject.tag=="plane"){
Destroy(gameObject);
}
}
The difference between these two methods:
the collider with trigger can enter into the other object while it only conflict at the edge without trigger.
No comments:
Post a Comment