- Home /
Question by
attagamerxd · Nov 10, 2018 at 08:03 PM ·
enemywander
please help! i am making an anemy wonder but it does not work
public float movespeed = 3f;
public float rotspeed = 100;
private bool iswandering = false;
private bool isrotleft = false;
private bool isrotright = false;
private bool iswalking = false;
void Update()
{
if(iswandering == false)
{
StartCoroutine(wander());
}
if(isrotright == true)
{
transform.Rotate(transform.up * Time.deltaTime * rotspeed);
}
if (isrotleft == true)
{
transform.Rotate(transform.up * Time.deltaTime * -rotspeed);
if (iswalking == true)
{
transform.position -= transform.forward * movespeed * Time.deltaTime;
}
}
}
IEnumerable wander()
{
int rotime = UnityEngine.Random.Range(1, 3);
int rotwait = UnityEngine.Random.Range(1, 4);
int rotLorR = UnityEngine.Random.Range(1, 2);
int walkwait = UnityEngine.Random.Range(1, 4);
int walktime = UnityEngine.Random.Range(1, 5);
iswandering = true;
yield return new WaitForSeconds(walkwait);
iswalking = true;
yield return new WaitForSeconds(walktime);
iswalking = false;
yield return new WaitForSeconds(rotwait);
if(rotLorR == 1)
{
isrotright = true;
yield return new WaitForSeconds(rotime);
isrotright = false;
}
if (rotLorR ==2)
{
isrotleft = true;
yield return new WaitForSeconds(rotime);
isrotleft = false;
}
iswandering = false;
}
}
Comment