void Update() { if (Input.GetKeyDown(KeyCode.E)) { for (int i = 0; i < PrisonerPrefab.Length; i++) { Invoke("_prisoner[i].callRollCall()", UnityEngine.Random.Range(1, 5)); } } } 

From unit console:

Trying to Invoke method: PrisonsAI._prisoner [i] .callRollCall () couldn't be called.

  • Your code cannot determine the cause of the error. Give the code for the whole class. The first thing that catches your eye is: i < PrisonerPrefab.Length , and then you call methods on _prisoner[i] , shouldn't there be PrisonerPrefab[i] ? - Mikhail Murugov
  • Also in Unity, it is advisable to avoid the Invoke method, because it greatly affects performance. - Mikhail Murugov
  • Yes, thanks, I have already decided everything myself !!!)) - Maximus

1 answer 1

 void Update() { if (Input.GetKeyDown(KeyCode.E)) { for (int i = 0; i < PrisonerPrefab.Length; i++) { Invoke("_prisoner[" + i + "].callRollCall()", UnityEngine.Random.Range(1, 5)); } } }