I created a walk script where it starts off on an original speed which is 10. I created a couple of if statements where if the player walks into Trigger number one, his speed becomes faster. I tried testing it but once the player enters the first trigger, he keeps his original speed. Is there any way to cancel the previous if statements?
Move Script:
{
public float speed = 10.0F;
public float speed1 = 10.0F;
public float speed2 = 20.0F;
public float speed3 = 30.0F;
public float speed4 = 40.0F;
public float speed5 = 50.0F;
void Start()
{
}
// Update is called once per frame
public void Update()
{
float translation = Input.GetAxis("Vertical") * speed;
float straffe = Input.GetAxis("Horizontal") * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate(straffe, 0, translation);
}
public void OnTriggerEnter(Collider col)
{
if(col.name == "Change Speed Trigger 0")
{
float translation = Input.GetAxis("Vertical") * speed1;
float straffe = Input.GetAxis("Horizontal") * speed1;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Debug.Log("Speed 1");
}
if (col.name == "Change Speed Trigger")
{
float translation = Input.GetAxis("Vertical") * speed2;
float straffe = Input.GetAxis("Horizontal") * speed2;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Debug.Log("Speed 2");
}
if (col.name == "Change Speed Trigger 2")
{
float translation = Input.GetAxis("Vertical") * speed3;
float straffe = Input.GetAxis("Horizontal") * speed3;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Debug.Log("Speed 3");
}
if (col.name == "Change Speed Trigger 3")
{
float translation = Input.GetAxis("Vertical") * speed4;
float straffe = Input.GetAxis("Horizontal") * speed4;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Debug.Log("Speed 4");
}
if (col.name == "Change Speed Trigger 4")
{
float translation = Input.GetAxis("Vertical") * speed5;
float straffe = Input.GetAxis("Horizontal") * speed5;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Debug.Log("Speed 5");
}
}
}