碰撞检测:
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Sphere")
{
print("Sphere");
_rigidbody.AddExplosionForce(explosionForce,collision.gameObject.transform.position,rudiusValue);
}
if (collision.gameObject.name.Contains("Cube"))
{
print("Collision happened");
}
}
private void OnCollisionStay(Collision collision)
{
print("Collision Stay");
}
private void OnCollisionExit(Collision collision)
{
print("Collision Exit");
}
触发检测:
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name.Contains("Cube"))
{
Destroy(other.gameObject);
this.gameObject.transform.localScale -= new Vector3(1, 1, 1) * 0.1f;
}
if (other.gameObject.CompareTag("Cube"))
{
print("CubeTrigger");
}
}
private void OnTriggerStay(Collider other)
{
print("TriggerEnter:" + other.gameObject.name);
}
private void OnTriggerExit(Collider other)
{
print("TriggerEnter:" + other.gameObject.name);
}