delaying the start of a navmesh agent

Hi.
I am making a 1st person version of pacman and I’m having trouble with the ghost ai.
I’ve based the way they navigate the maze on the original namco arcade game.

The problem I’m having is when the ghosts start to move and what “mode” they are in. I have variables set up so that each of the 4 ghosts start when a certain amount of dots have been eaten. 2 of them are set to 0, 1 is set to 30 and the 4th is set to 60. This works as intended, but the “mode” also doesn’t start until the ghost does.
I only have 2 of the 3 ghost modes so far, “chase” and “scatter”. “Frightened” will come later and will no doubt be a whole new problem!

For simplicity, the modes always last the same amount of time…7 seconds of “scatter” followed by 20 seconds of “chase” and repeat. The 2 ghosts that start on 0 dots, start in “scatter” mode. If I eat 30 dots when they are in “chase” mode, the 3rd ghost will become active and be in “scatter” mode when he should be in the same mode as the others.

So, how would I go about delaying the start of a ghost but keep his mode in line with already active ghosts?

I shall keep plugging away trying things but chopping things out of 1 script and putting in another is confusing me and just breaks everything :smiley:

my ghost code… ignore “ghostMode”, that is for when I do the “frightened” mode

using UnityEngine;
using System.Collections;

public class GhostAI : MonoBehaviour 
{
	public static int ghostDots;
	public int startDots;
	public Transform chase;
	public Transform scatter;
	private int ghostMode = 1;

	public int chaseSeconds = 20;
	public int scatterSeconds = 7;
	private float currentSeconds = 0f;
	
	private NavMeshAgent agent;
	
	void Start () 
	{
		agent = gameObject.GetComponent<NavMeshAgent>();

	}
	void Update()
	{
		ghostDots = EatingScript.dotCount;
		
		currentSeconds += Time.deltaTime;

		if (ghostDots > startDots) {

			if (currentSeconds < scatterSeconds && ghostMode == 1) {
				agent.SetDestination (scatter.position);
				//Debug.Log("Scatter Mode");
			}

			if (currentSeconds > scatterSeconds && ghostMode == 1) {
				agent.SetDestination (chase.position);
				//Debug.Log("Chase Mode");
			}

			if (currentSeconds > chaseSeconds && ghostMode == 1) {
				currentSeconds = 0;
			}
		}
	}
}

It may be happening because all of the monsters have there own script, maybe create a “MonsterManager” script which handles the amount of monsters in an array or list and also which mode they are in. This would allow you to have functions to retrieve information about the monster or mosters whilst keeping them in the same state

Hope this helped