I want to make my ai of enemy to wait on the edge of the platform for 3 seconds
How can i do this? I want to use IEnumarator method but i think i done it wrong
PLEASE HELP Me in this!
using UnityEngine;
using System.Collections;
public class EnemyPatrol : MonoBehaviour {
public float moveSpeed;
public bool moveRight;
public Transform wallCheck;
public float wallCheckRadius;
public LayerMask whatIsWall;
private bool hittingWall;
private bool notAtEdge;
public Transform edgeCheck;
public float enemyWaitTime;
void Start ()
{
}
void Update () {
hittingWall = Physics2D.OverlapCircle (wallCheck.position, wallCheckRadius, whatIsWall);
notAtEdge = Physics2D.OverlapCircle (edgeCheck.position, wallCheckRadius, whatIsWall);
if(hittingWall || !notAtEdge)
moveRight = !moveRight;
if (moveRight)
{
StartCoroutine(WaitTime());
transform.localScale = new Vector3 (0.75f, 0.75f, 1f);
GetComponent().velocity = new Vector2(moveSpeed, GetComponent().velocity.y);
} else {
StartCoroutine(WaitTime());
transform.localScale = new Vector3 (-0.75f, 0.75f, 1f);
GetComponent().velocity = new Vector2(-moveSpeed, GetComponent().velocity.y);
}
}
IEnumerator WaitTime() {
yield return new WaitForSeconds (enemyWaitTime);
}
}
↧