So, I have a projectile prefab that is shot both by the player and by the turrets of my game. When I instance the prefab in the two different scripts, I give them two different tags, "wormProjectile" and "enemyProjectile". Because I didn't want to projectile to live forever, I attached a script to the prefab meant to kill it after a certain amount of time. I wanted the projectiles fired by the turrets to live a different length of time than the ones fired by the player, so I tried using the following script:
But it never goes into the if statements. I am sure my mistake is something simple, but can anyone help me? Thank you! I really appreciate it.
I suspect Awake is called during Instantiate, and your problem seems to confirm that: since you set the tag after Instantiate, Awake only sees the original prefab tag.
... bullet = Instantiate(prefab, ...); Destroy(bullet, 1); // if bullet isn't a GameObject, use bullet.gameObject bullet.tag = "wormProjectile"; ...
answered Oct 20 '11 at 08:30 PM