- Home /
Destroy Cloned Object on Collision
hello uniters,
i would like to destroy an object that is cloned on collision the specific object is cloned beforehand, and i would like to destroy the one specific that collides with the player. now i have the problem that sometimes another cloned object gets destroyed instead. not the one actually triggering the onCollision Destroy.
here you can check out what i got so far
this is my function:
function OnCollisionEnter(collision:Collision)
{
if( collision.gameObject.tag == "Player" )
{
Instantiate(GameObject.FindWithTag("Exp"), transform.position, Quaternion.identity);
Destroy(collision.gameObject.Find("ShootBomb(Clone)"));
}
}
additional ramble:
Obviously far from finished, the art,music and fonts are either from public tutorials or the asset store / my iTunes library and not credited yet, as i plan to replace them, once the mechanics work as they should. and really the only two things in my way are the wrong destructions of the bombs, and an animated player character. (the game is initially made for android (specifically the htc one mini) so you need to move the player to trigger a bomb, on the phone the mechanics work a bit better, as the gyro acceleration makes it extremely difficult to keep the player in place.
Answer by Ibzy · Jun 23, 2015 at 03:12 PM
Try this:
GameObject bombClone = Instantiate(GameObject.FindWithTag("Exp"), transform.position, Quaternion.identity) as GameObject;
Destroy(bombClone);
This gives you a reference to the object you instantiated and then allows you to destroy it specifically. I assume there is some form of delay between these 2 actions though?
Your answer
Follow this Question
Related Questions
clone functions 2 Answers
Object Collision PLEASE HELP!!! 1 Answer
My Javascript collision isn't being detected, please help. 0 Answers
Destroy Clones One At A Time Javascript 0 Answers
Detect collision and destroy one object 0 Answers