- Home /
Help with C# - destroy at a certain position not working
Hello. Im very new to programing so still have a lot to learn. But have been learning through reading the documentation, youtube tutorials and these forums.
I have a simple game where stuff f.e. cubes randomly spawn and go twards the player. So I wanted to make a simple script to make the cubes despawn when they go behind the player (player position is Z = -100).
My Script:
public class destroyUnderZvalue : MonoBehaviour
{
public float destroyPosition = -105.0f;
void update()
{
if (transform.position.z <= destroyPosition)
{
Destroy (gameObject);
}
}
}
Tho I dont know it its <= or >= since the value is lower (-105 is lower than -100)
But when I attatch it to the cubes it does nothing. Thank you in Advance.
Answer by Aridez · Jul 13, 2015 at 01:26 AM
In "void update()" the u must be capital. Change it for "void Update()", I've tested it with the changes and it's working.
Thank you. Lol now i feel silly that i didn't notice it. :)
Your answer
Follow this Question
Related Questions
Any way to change transform.position of an indefinite number of gameobjects on FixedUpdate? 2 Answers
If transform.position != previousposition not working properly. 2 Answers
GameObject.transform.position on the y axis keeps changing even though object is stationary 1 Answer
Distribute terrain in zones 3 Answers
Subtracting the position of transform from the position of Game Objects in a list. 1 Answer