using System.Collections; using System.Collections.Generic; using UnityEngine; public class WanderingAI : MonoBehaviour { public float moveSpeed = 3f; public float rotSpeed = 100f; private bool Iswandering = false; private bool Isrotatingleft = false; private bool Isrotatingright = false; private bool Iswalking = false; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if(Iswandering == false) { StartCoroutine(Wander()); } if(Isrotatingright == true); { transform.Rotate(transform.up * Time.deltaTime * moveSpeed); } if(Isrotatingleft == true); { transform.Rotate(transform.up * Time.deltaTime * -moveSpeed); } } } IEnumerator Wander() { int rotTime = Random.Range(1, 3); int rotateWait = Random.Range(1,4); int rotateLorR = Random.Range(1,2); int walkWait = Random.Range(1,4); int walkTime = Random.Range(2,5); Iswandering = true; yield return new WaitForSeconds(walkWait); Iswalking = true; yield return new WaitForSeconds(walkTime); Iswalking = false; yield return new WaitForSeconds(rotateWait); if(rotateLorR == 1) { Isrotatingright = true; yield return new WaitForSeconds(rotTime); Isrotatingright = false; } if(rotateLorR == 2) { Isrotatingright = true; yield return new WaitForSeconds(rotTime); Isrotatingleft = false; } Iswandering = false; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)