using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;

public class SpeedEvent : MonoBehaviour {

    FirstPersonController fpsController;

    public float normalSpeed;
    public float fastSpeed;

	// Use this for initialization
	void Start () {
        fpsController = GetComponent<FirstPersonController>();
        EventManager.OnSpeedStart += StartSpeedEvent;
        //StartSpeedEvent(20);
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void StartSpeedEvent(float time)
    {
        StartCoroutine(SpeedTimer(time));
    }

    IEnumerator SpeedTimer(float time)
    {
        fpsController.SetSpeed(fastSpeed);
        yield return new WaitForSeconds(time);
        fpsController.SetSpeed(normalSpeed);
    }
}
