For some reason my if statement is being ignored and it will pass it going right to the else statement instead. Here is my code,
using UnityEngine;
public class Slide : MonoBehaviour {
public float speed = 0.1f;
private float posY = 5.75f;
private string movement = "neutral";
public void SlideDown() {
movement = "down";
//transform.position = new Vector3(-3.087039f, 5.75f, 5.192412f);
}
public void SlideUp() {
movement = "up";
//transform.position = new Vector3(-3.087039f, 9.5f, 5.192412f);
}
void Update() {
if(movement == "down")
if (posY > 5.75) {
posY -= speed;
transform.position = new Vector3(-3.087039f, posY, 5.192412f);
}else{
movement = "neutral";
transform.position = new Vector3(-3.087039f, 5.75f, 5.192412f);
Debug.Log("down");
}
if (movement == "up")
if (posY < 9.5) {
posY += speed;
transform.position = new Vector3(-3.087039f, posY, 5.192412f);
}else{
movement = "neutral";
transform.position = new Vector3(-3.087039f, 9.5f, 5.192412f);
Debug.Log("up");
}
}
}
I don’t know what is wrong, please help.