Hello.
Currently I’m trying to move an object up and down with if statements on the y axis. The object is a spike that if the player touches dies.
This is the script I’m using. I want to have the spike move up to a certain point on the y axis and when it hits it to move down until it hits another point and then have it move up again. It’s probably worth noting that i have the spike attached to an empty game object so its starting position is always 0.
function Update() {
if (this.transform.position.y <= 0){
this.transform.position.y = this.transform.position.y + (10*Time.deltaTime);
}
if (this.transform.position.y >= 10){
this.transform.position.y = this.tranform.position.y - (5*Time.deltaTime);
}
}
function OnTriggerEnter (other :Collider){
Application.LoadLevel("Game Over");
}
Right now this script will move the spike up 10 on the y axis but then it will stop there and not go back down. Any help would be greatly appreciated !