Hi - in this script when the player is inside a trigger, his movement speed is reduced to 1.
On exiting the trigger - I want his movement speed to go back to the normal value.
However - although his movement speed is reduced on entering the trigger - on exiting it, it remains as the slow value and doesn’t go back to normal.
Does anyone know what I’m doing wrong?
using UnityEngine;
using System.Collections;
public class SlowDown : MonoBehaviour
{
public float slowSpeed = 1;
private float normSpeed = 7;
void OnTriggerEnter(Collider player)
{
normSpeed = player.GetComponent<Movement>().speed;
player.GetComponent<Movement>().speed = slowSpeed;
}
void OnTriggerExit(Collider player)
{
player.GetComponent<Movement>().speed = normSpeed;
}
}
Best, Laurien