- Home /
Question by
Obinsonray · Sep 11, 2011 at 07:48 AM ·
prefabtriggerdestroy
'Picking up Ball' by destroying Prefab, prefab does not get 'read'
Ok so Initially I have a gameobject (BasketBall) when it is collided with, it is destroyed and BallShot is set to true so you "picked up the ball" then you shoot out a Prefab of the BasketBall (BasketBall(Clone)), my collision will not trigger the second if statement, what is wrong?
static var BallShot = false;
function OnTriggerEnter (BallCollide : Collider) {
if(BallCollide.gameObject.name == "BasketBall"){
BallShot=true;
Destroy(gameObject.Find("BasketBall"));
Debug.Log(BallShot);
if(BallCollide.gameObject.name == "BasketBall(Clone)"){
BallShot=true;
Destroy(gameObject.Find("BasketBall(Clone)"));
Debug.Log(BallShot);
}
}
}
Comment
Best Answer
Answer by henry96 · Sep 11, 2011 at 08:37 AM
Hmmmmmmm..... Your script is kinda repetitive. Try to use tag instead of name. For example : if(BallCollide.gameObject.tag == "BasketBall")
so you don't need to write your same code twice. And for the part
Destroy(gameObject.Find("BasketBall(Clone)"));
You could just write
Destroy (BallCollide.gameObject);
Anyway, I hope the changing from name to tag can solve your problem! ^^