private void ExecuteAI()
{
//get random number
if(!gameObject.active)
{
//only update if running
return;
}
//generate command randomly,
//the first 10 is used, high number wont make any effect
int i = Random.Range(0, 20);
float nextTime = aiSpeed;
//execute one of the command based on the value
switch(i)
{
case 0:
//stop for a bit
speed = 0;
direction = 0;
nextTime += 2;
model.Health = AquaSphere.MODEL.HealthType.HEALTHY;
break;
case 1:
//accelerate
speed += acceleration;
nextTime += 3;
model.Health = AquaSphere.MODEL.HealthType.SICK;
break;
case 2:
//slow
speed -= acceleration;
nextTime += 2;
model.Health = AquaSphere.MODEL.HealthType.HEALTHY;
break;
case 3:
//right
direction += rotation;
break;
case 4:
//left
direction -= rotation;
break;
case 5:
//face straight
direction = 0;
break;
//
case 6:
//run!!
speed = maxSpeed;
nextTime +=3;
break;
case 7:
//spin a bit
direction += rotation * 1.3f;
nextTime = 1;
break;
case 8:
//back and turn
direction = rotation * 1.2f;
speed = minSpeed;
nextTime = 2;
break;
case 9:
//back and turn
direction = rotation * -1.2f;
speed = minSpeed;
nextTime = 2;
break;
case 10:
//rest a bit
direction = 0;
speed = 0;
nextTime = 5;
break;
default:
//nothing
break;
}
Invoke("ExecuteAI", nextTime);
}