Hello everyone, I just wanted to know if there is a way to check if a GameObject collides with another simply.
In ActionScript for example, there is a Method that is called ‘hitTest’. with that, you can determine easily if an Object is in collision with another object.
for example in Flash:
if( firstObject.hitTest(secondObject) ){
print("Object A Collides with Object B");
}
In Unity you have to create a script that you will put in a GameObject that will be something like that:
#pragma strict
static public var collisionWithObjectB:boolean;
public var ObjectB:GameObject;
function Start(){
collisionWithObject = false;
}
function OnCollisionStay(collision:Collision){
if(collision == ObjectB){
collisionWithObjectB = true;
}
}
function OnCollisionExit(collision:Collision){
if(collision == ObjectB){
collisionWithObjectB = false;
}
}
And after all of this we can check whether they collide or not, so I was looking for a way (if there is any.) to make this process faster. Thanks in advance.
What if I want to refer to two object from another script?
For example, in Flash, you can check if two objects collide with one another by doing something like this:
if(ObjectA.hitTest(ObjectB)){/This will return true if those two object collide./}
I simply don’t want to be forced to create a script as a component in every GameObject that needs to be checked for collision purposes, but instead being able to refer to the collision between those two (or more.) from another script.