Description
The contact points generated by the physics engine.
Every contact contains a contact point, normal and the two colliders that collided (see ContactPoint).
From inside OnCollisionStay or OnCollisionEnter you can
always be sure that contacts has at least one element.
function OnCollisionStay(collision : Collision) {
for (
var contact :
ContactPoint in collision.contacts) {
print(contact.thisCollider.name +
" hit " + contact.otherCollider.name);
Debug.DrawRay(contact.point, contact.normal,
Color.white);
}
}
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
void OnCollisionStay(Collision collision) {
foreach (
ContactPoint contact
in collision.contacts) {
print(contact.thisCollider.name +
" hit " + contact.otherCollider.name);
Debug.DrawRay(contact.point, contact.normal,
Color.white);
}
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
def
OnCollisionStay(collision as Collision):
for contact as
ContactPoint in collision.contacts:
print(((contact.thisCollider.name + ' hit ') + contact.otherCollider.name))
Debug.DrawRay(contact.point, contact.normal,
Color.white)
var explosionPrefab :
Transform;
function OnCollisionEnter(collision : Collision) {
var contact = collision.contacts[0];
var rot =
Quaternion.FromToRotation(
Vector3.up, contact.normal);
var pos = contact.point;
Instantiate(explosionPrefab, pos, rot);
Destroy (gameObject);
}