There is a sphere and a cube. How to make so that when a collision with a cube sphere was removed?
The cube hung such a script, but he removes the cube himself:
private void oncollisionenter (Collision Collision)
{
Float Posx, Posy, Posz;
POSX = transform.position.x;
POSY = transform.position.y;
Posz = transform.position.z;
Destroy (GameObject);
}
Answer 1, Authority 100%
if (collision.gameobject.name == "sphere_name") {
Destroy (Collision.GameObject);
}
or
if (collision.gameobject.compareteag ("sphere_tag") {// if (Collision.gameObject.tag == "Sphere_tag")
Destroy (Collision.GameObject);
}
Answer 2
Check is not required. In your case, the code will be the following
private void oncollisionenter (Collision Collision)
{
Float Posx, Posy, Posz;
POSX = transform.position.x;
POSY = transform.position.y;
Posz = transform.position.z;
Destroy (Collision.GameObject);
}