Ok, I’m having a ball that when colliding to random objects I want to Destroy that objects, but in order to do that I have to refer to them somehow or else the script won’t know in what I’m referring.
If it was a real world situation I would simply tell it:
if (ball.collides(something)){
Destroy(something);
}
However I lack the programming language to translate it into JavaScript language. Any help?
If you attach a rigidbody to your ball you will get OnCollisionEnter OnCollisionStay and OnCollisionExit functions you can use i your script
The OnCollision functions have an object of the class “Collision” as parameter. this class contains the collider and the gameobject the rigidbody collided with.
The thing is, I don’t want to specify the collider because if I do that, then the collision effect with only apply with that specific collider.
I’m struggling to find a way to do that and to make it do a collide effect with a specific collider is easy, the hard thing is to tell it when it collider, then that effect would be applied to the collider whoever it is.
If I wanted to be more specific about the collider properties I could simply tell it something that “if (collider.name == “lalala”) {[that happens.]}”
The whole thing is that the thing keeps asking me “Who’s the collider?” all the time I simply want to tell it “WHATEVER IT IS!!!” so I really have the problem with the “if(collider.name == “lalala”…)”
I’ve tried every possible combination of all the things you gave me see it the script reference but nothing actually worked…
I have even tried “OnCollisionEnter(Collision : collision)” (With both caps and not in the initiative letter. in “collision” both “collision and “Collision””) what else should I do to make it understand that I don’t want to specify the collider?
If you want a collision to apply to anything, don’t put any conditional statements that refer to specific traits about the colliding object. For example, this will print messages in the console when a collision happens with any gameObject:
function OnCollisionEnter(collidingObject : Collision)
{
// Log that there was a collision
Debug.Log("There was a collision");
// Log the name of the colliding object
Debug.Log("Colliding Object: " + collidingObject.gameObject.name);
// Destroy the colliding Object
Destroy(collidingObject.gameObject);
}
Additionally, aside from having a colliders on your objects and a rigidbody on at least one, there are no other implicit conditions needed for unity to detect the collision.