Hi, I’ve got an elevator that goes up and down if a button is pressed, but I’m trying to put some lines into the code so that if the player falls or jumps off the structure, the elevator will return to its initial place, by playing the DOWN animation, so the player can go back up.
The y transform position of the player when they go up the structure is 16, so I thought that if the player’s y position was less than that after the UP animation had been played, that would indicate the player had fallen or jumped from the structure.
Whilst the code is running, the results are weird and not what I’m trying to do.
Any insight would be greatly appreciated.
PS, this isn’t the whole code, but the part that I believe pertains to my problem.
public Transform player;
public float playerPosition;
public float heightPosition = 16f;
private bool pressedButton = false;
private bool isElevatorUp = false;
void Update()
{
{
if (player.position.y < heightPosition)
{
if (isElevatorUp == true)
{
DOWN();
}
}
}
}
void DOWN() {
target = GameObject.Find("ELEVATOR");
target.GetComponent<Animation>().Play("DOWN");
}