- Home /
onCollisionEnter function called from another object.
Is it possible to make something like this:
var objectToTest:GameObject;
function Update () {
if(objectToTest.collider.OnCollisionEnter){
print("objectToTest collided with something!");
}
}
?
so to define what happens OnCollisionEnter from outside the object that actually collides? thanks in advance
Answer by qJake · Sep 28, 2010 at 02:39 AM
No, you can't, because functions are not boolean variables. You need to set up a state in the other script, like this:
public bool isColliding = false;
void OnCollisionEnter(Collision o) { isColliding = true; }
void OnCollisionExit(Collision o) { isColliding = false; }
Then just read the bool.
Your answer
Follow this Question
Related Questions
Detect collision with specified object 1 Answer
OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer
Smooth movement for the block upon player collision,Smooth box movement 0 Answers
Help with collisions and destroy please 1 Answer
Play sound on collision doesn't work 1 Answer