unity 3d student

Beginner B01 – Basic Collision Detection

How to detection basic collisions between objects using scripting.

Code Used

//Basic collision detection checking for two differently named objects
  1. function OnCollisionEnter(theCollision : Collision){
  2.  if(theCollision.gameObject.name == "Floor"){
  3.   Debug.Log("Hit the floor");
  4.  }else if(theCollision.gameObject.name == "Wall"){
  5.   Debug.Log("Hit the wall");
  6.  }
  7. }

Further Reading

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

100 Comments