Powerup issue - Speed

Hi All,

I am currently making a speed powerup for a game, which I’m mainly struggling with resetting the value back to its original. It is mainly due to the fact that I need to access the speed variable from another script, as i want to say: On collision of this object → increase speed → wait for 5 seconds → speed is set back to original. Some help would be great! Thankyou.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedPowerup : MonoBehaviour {

	public float fasterSpeed;
	public bool isFaster = false;
	public float f = 100;

	public void OnTriggerEnter(Collider other) {

		if (other.tag == "Player") {
			isFaster = true;
			Debug.Log ("Speed Powerup");
			PlayerMovement theSpeed = other.gameObject.GetComponent<PlayerMovement> ();
			theSpeed.speed = fasterSpeed;
			StartCoroutine (WaitTime ());
		}
	}

	public IEnumerator WaitTime() {
		yield return new WaitForSeconds (5);
		isFaster = false;
	}
}

@bradarnott

What you needed for your coroutine to work was a reference to your PlayerMovement

	public void OnTriggerEnter(Collider other) 
	{

		if (other.tag == "Player") {
			isFaster = true;
			Debug.Log ("Speed Powerup");
			PlayerMovement theSpeed = other.gameObject.GetComponent<PlayerMovement> ();
			theSpeed.speed = fasterSpeed;
			StartCoroutine ("WaitTime", theSpeed);
		}
	}


	public IEnumerator WaitTime(PlayerMovement playerSpeed) 
	{
		yield return new WaitForSeconds (5);
		isFaster = false;
        playerSpeed.speed =100;
	}