I want to make my enemy character to get a random rotation, then move for about 3 sec, then stay get a new rotation and move again. And keep doing that until the player comes in range.
Here is my code:
function Idle()
{
while(true)
{
if(dist > awareDist)
{
randRotation();
yield WaitForSeconds(5);
walkRandom();
yield WaitForSeconds(5);
}
}
}
function randRotation()
{
transform.rotation = Quaternion.AngleAxis(Random.Range(-40,40), Vector3.up);
}
function walkRandom()
{
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var controller : CharacterController = GetComponent(CharacterController);
controller.SimpleMove(forward * speed);
}
The Idle function is called from Start. Animations will be added. dist is the distance to the palyer.