Hello I am having some trouble with my IEnumerator function in which the variables I give the function do not seem to work. My script calls the IEnumerator function but nothing is ever executed in the function. I am assuming there is some special way of passing in variables but I have not found anything that has worked. Feel free to reference my script and thanks for the help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class slowMovement : MonoBehaviour {
public int damage;
public float time;
public float newSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider col) {
if (col.GetComponent<Collider>().tag == "LocalPlayer") {
Debug.Log ("hit the remoteplayer");
var hit = col.gameObject;
var health = hit.GetComponent<Health> ();
var movement = hit.GetComponent<PlayerController> ();
if (health != null) {
health.TakeDamage (damage);
}
if (movement != null) {
movement.speed = newSpeed;
StartCoroutine (timeDelay (time, movement));
}
Destroy (gameObject);
}
}
IEnumerator timeDelay (float time, PlayerController move) {
yield return new WaitForSeconds (time);
move.speed = 5f;
}
}