I want to code to make an enemy move in a random direction every so often, so i have created a random number generator system where depending what number is called it moves in a different location, however it doesn't seem to work and will either not work at all or will not stop moving;
It is for a top down 2D shooter.
Code:
{
public float moveSpeed;
public float moveChance;
public float moveTime;
public bool IsRoaming;
public bool IsRoamingUp;
public bool IsRoamingLeft;
void FixedUpdate ()
{
Roaming ();
RoamMoveUp ();
}
void Roaming ()
{
if ((moveChance == 0))
{
moveChance = Random.Range(0, 0);
}
if ((moveChance == 1))
{
IsRoamingUp = true;
}
}
void RoamMoveUp ()
{
if (IsRoamingUp = true)
{
moveTime++;
transform.position += Vector3.up * moveSpeed;
if (moveTime > 10)
{
Debug.Log("ItsWorking!");
moveChance = Random.Range (0, 0);
IsRoamingUp = false;
moveTime = 0;
}
}
}
}
↧