I am making a top down shooter game but I cannot get this last mechanic to work. After one enemy has detected the player, if the player remains detected the enemy should notify all other enemies to move towards the player.
I have tried using events and delegates but to no avail. All the enemies use the same script “Enemy Controller” and therefore when I set a boolean in one enemy it only changes on the one enemy. This is the crux of my problem.
So you’re trying to have all enemies become active and chasing when any enemy sees the player? You could use a public static bool, which only one instance of is stored and all copies of the script reference - example:
public static bool playerSpotted;
// If player is spotted:
playerSpotted = true; // This updates the public static bool playerSpotted, which every copy of this script shares.
if(playerSpotted == true) // true if ANY copy of this script has spotted the player.
// Move towards the player