유니티(UNITY) / OnCollisionEnter / OnTriggerEnter

댓글수0 다음블로그 이동

유니티

유니티(UNITY) / OnCollisionEnter / OnTriggerEnter

Huga Gage
댓글수0


OnCollisionEnter / onTriggerEnter

OnCollisionEnter 는 충돌지점, 충돌속도등의 정보를 포함하므로 계산이 늘어남.

충돌지점, 충돌속도등을 사용하지 않을 경우에는 onTriggerEnter 쓰는 게 부하관리상 좋음.


OnCollisionEnter는 충돌되는 물체에 리지드 바디가 필요함.

OnTriggerEnter는 충동체 만으로 충분.


-------------------------------------

MonoBehaviour.OnCollisionEnter(Collision)
Description

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
In contrast to onTriggerEnter, onCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.

    function onCollisionEnter(collision : Collision) {
        // Debug-draw all contact points and normals
        for (var contact : ContactPoint in collision.contacts)
            Debug.DrawRay(contact.point, contact.normal, Color.white);
       
        // Play a sound if the coliding objects had a big impact.       
        if (collision.relativeVelocity.magnitude > 2)
            audio.Play();
    }

OnCollisionEnter can be a co-routine, simply use the yield statement in the function.


맨위로

http://blog.daum.net/zevie/13

신고하기