Hello. I am doing the example Space Shooter from tutorials and using Unity 4.3.4f1.
According to the tutorial, clones should disappear from hierarchy view but mine is still there, only the triangle on the left disappears. But I see that the Z position of the clone is increasing, so I guess the object doesn’t stop. Is this expected?
I think I did everything same as tutorial. This is the code from tutorial:
public class PlayerController : MonoBehaviour
{
...
void Update ()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
}
...
}
public class DestroyByBoundary : MonoBehaviour {
void OnTriggerExit (Collider other)
{
Destroy(other.gameObject);
}
}
Hi. Try putting the DestroyByBoundary script on the same gameObject as the one that has the PlayerController script.
The Destroy ( other.gameObject ), function is destroying whichever gameObject your collider is on. I haven’t seen the tutorial, but it’s likely that this DestroyByBoundary script needs to be on the top level gameObject, so that the object deleted includes the entire hierarchy.
You will need a collider on the top level, but I’m guessing that there will be one there. It’s likely this is the same object that the PlayerController script will be on.
To explain, if you have the script on a lower element, like the ‘sphere’ in my screen shot, it will only delete the sphere. If you have it on the SpaceShip (highlighted blue), then everything will be destroyed.
Once you have an answer you’re happy with (doesn’t have to be this one), please remember to upvote it and tick it as an accepted answer, to help others who might have a similar problem).