Trouble with coroutine
I am wondering if coroutine has become obsolete because I tried every example I could find and none have worked, the following is what I have now (My question is posted a little lower in all caps.): using System.Collections; using System.Collections.Generic; using UnityEngine; public class meatBeetle : MonoBehaviour { public Transform player; public float damage = 5; bool attackReady = false; // Use this for initialization void Start () { StartCoroutine("DoCheck"); } // Update is called once per frame void Update () { if(Vector3.Distance(player.position, this.transform.position) < 10) { Vector3 direction = player.position - this.transform.position; direction.y = 0; this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f); if(direction.magnitude > 0.75) { this.transform.Translate(0, 0, 0.05f); } if (direction.magnitude < 2) { if (attackReady == true) doDamage(); } } } void doDamage() { player.SendMessage("ApplyDamage", damage); Debug.Log("sent damage message"); } IEnumerator DoCheck() { for (; ; ) { // execute block of code here attackReady = true; yield return new WaitForSeconds(3f); } } }
WHAT I AM TRING TO DO IS PUT A TIMER ON THIS
if (direction.magnitude < 2) { if (attackReady == true) doDamage(); }
Please note it was originally written like this:
if (direction.magnitude < 2) { player.SendMessage("ApplyDamage", damage); Debug.Log("sent damage message"); }