Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

PLEASE Help with 2d Enemy AI system, How to make him wait?

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 1488


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>