Option 1
function MakeDecision(int lastDecision)
{
// Stop the call back
CancelInvoke(“MakeDecision”);
// ReStart the call back with a new Random.Range
InvokeRepeating(“MakeDecision”, Random.Range(1,6);
// return another random decision or one
// guaranteed to be different?
// Random (might be the same decision again)
return Random.Range(1,2);
OR
// guaranteed to be different.
// coded as a case statement in the event
// you have many states and want to do other stuff
switch (lastDecision)
{
case 1:
return 2;
case 2:
return 1;
}
OR
// always step to the next decision
// and roll over when at the end
return (++LastDecision % 3);
// this would generate 0, 1, 2, 0, 1, 2
return (++LastDecision % 3) + 1;
// this would generate 1, 2, 3, 1, 2, 3
}
Note, I haven’t tried call back from inside a call back but I don’t see why it shouldn’t work.
Option 2
Lower the original timer to 1 second intervals.
function Start()
{
InvokeRepeating(“MakeDecision”, 0, 1);
}
Then…
function MakeDecision(int PreviiousDecision)
{
// 50% to keep on trucking
if (Random.Range(1,2) == 2)
return PreviousDecision;
// roll the dice again
return Random.Range(1,2);
}
Ultimately a lot depends on how erratic or how smooth you want your behavior to be.
Charles