hello! I know that questions similar to this have been answered but I am kind of new to C# coding so I don’t understand too much on how to fix my code so it sends the messages to the enemies, if you can help me it would be really helpful but here is my code:
public static bool GameIsPaused = false;
public bool isResumed = true;
public GameObject pauseMenuUI;
GameObject[] AIEnemies;
private void Start()
{
AIEnemies = GameObject.FindGameObjectsWithTag("EnemyAI");
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
if(GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
void PauseandResumeAI ()
{
if(isResumed)
{
foreach (GameObject enemy in AIEnemies)
{
enemy.SendMessage("Pause");
}
}
else if(!isResumed)
{
foreach (GameObject enemy in AIEnemies)
{
enemy.SendMessage("UnPause");
}
}
}
public void Resume ()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
isResumed = true;
GameObject.Find("MainCharacter").SendMessage("EnableHealth");
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
isResumed = false;
GameObject.Find("MainCharacter").SendMessage("DisableHealth");
}
I would love it if you could help me, thanks!