Hi :),
I have question about Collisions.
Let's say i have 2 GameObjects, Cube1 with a BoxCollider (Cube1Collider) and a rigidbody and Cube2 with a BoxCollider (Cube2Collider) and a rigidbody.
Normally i attach this script on Cube1 to get information about the collision occuring between his Collider and others Colliders.
code (javascript) : function OnCollisionEnter(CollisionInfo:Collision) {
var CollidedCollider = CollisionInfo.gameObject.name; var Point:Vector3 = CollisionInfo.contacts[0].point; var Normal:Vector3 = CollisionInfo.contacts[0].normal; Debug.Log(CollisionInfo.contacts[0].thisCollider.name+" hit "+CollisionInfo.contacts[0].otherCollider.name); Debug.Log("CollidedCollider : " + CollidedCollider); Debug.Log("Point : " + Point); Debug.Log("Normal : " + Normal);
}
This is working correctly, but i don't want to manage my program this way ! I don't want to attach many scripts to many GameObject and i want to be able to test the collision between Cube1 and Cube2 in code.
For example i want to attach a main script called "Program" to an Empty GameObject and be able to test collisions between 2 GameObjects in code. But i have not managed to do this so far...
It would look like this : code javascript : function Cube1Collider.OnCollisionEnter(CollisionInfo:Collision) {
var CollidedCollider = CollisionInfo.gameObject.name; var Point:Vector3 = CollisionInfo.contacts[0].point; var Normal:Vector3 = CollisionInfo.contacts[0].normal; Debug.Log(CollisionInfo.contacts[0].thisCollider.name+" hit "+CollisionInfo.contacts[0].otherCollider.name); Debug.Log("CollidedCollider : " + CollidedCollider); Debug.Log("Point : " + Point); Debug.Log("Normal : " + Normal);
}
But it doesn't work...
Do you have any idea how to achieve this ?
Thanks