Unity3d Collision Detection

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public classHitcheck:monobehaviour {///two objects can collide with the condition that two are all with collider and one of them is a rigid body. //Use this for initialization    voidStart () {}//Update is called once per frame    voidUpdate () {}/////////////////Trigger////////////////////    //just entering the trigger range.    voidOntriggerenter (Collider other) {print ("Enter trigger range"); }    //stays within the trigger range    voidOntriggerstay (Collider other) {print ("Continuous triggering"); }    voidOntriggerexit (Collider other) {print ("leave the trigger range"); }//////////////////collision-related three functions////////////////////    //the two objects that collide must have relative motion//It is called once at the beginning of the collision and "collision with ground will also trigger"    voidOncollisionenter (Collision other) {print ("Collision Start"); }    //have contact, and have relative movement    voidOncollisionstay (Collision other) {print (other.gameObject.name); if(string. Equals ("Cube2", Other.gameObject.name)) {Print ("There was a collision with Cube2."); } Print ("in Collision"); }    //End of collision    voidOncollisionexit (Collision other) {print ("End of collision"); }    ///////////////////////////////////////////}

Unity3d Collision Detection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.