I want to destroy a Game Object when it reaches a certain position on the z axis. Will this work?
if(transform.position.z == -30)
Destroy(gameObject);
I can’t seem to figure it out. Do I need to build a script calculating the distance traveled for it to work properly?
Theoretically yes. The problem with doing it that way is that if it jumps past -30 without hitting it it won’t get deleted. Try using (transform.position.z <= -30) instead
Just use this:
if(transform.position.z >= -30){
Destroy(gameObject);
}
You can’t use " == " because if the frame do not hit the “30Z” the object won’t be deleted.