OnCollisionEnter is not called in unity

前端 未结 6 1863
走了就别回头了
走了就别回头了 2021-01-04 06:10

I checked nearly every answer for this, but those were mostly simple errors and mistakes. My problem is that OnCollisionEnter is not called even when colliding whith other r

6条回答
  •  花落未央
    2021-01-04 06:49

    Try this

    http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

    using UnityEngine;
    using System.Collections;
    
    public class Example : MonoBehaviour {
      void OnCollisionEnter(Collision collision) {
    
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawRay(contact.point, contact.normal, Color.white);
        }
    
        if (collision.relativeVelocity.magnitude > 2){
            audio.Play();        
        }
    
      }
    }
    

提交回复
热议问题