I've been trying to work on a targeting system with a highest property value for all players within a game. Right now my code looks like this:
PlayerManager whoIsHighest = null;
var AllPlayers = FindObjectsOfType<PlayerManager>();
float highestFear = 100;
foreach( var p in AllPlayers)
{
if (p.currentFear >= highestFear || (whoIsHighest == null))
{
whoIsHighest = p;
highestFear = p.currentFear;
}
}
if (whoIsHighest != theHighest) theHighest = whoIsHighest;
if (theHighest != null && theHighest.currentFear >= 50)
{
Debug.Log(whoIsHighest.name);
Debug.Log("Testing");
AI.SetDestination(theHighest.transform.position);
}
It's grabbing all players that have the PlayerManager script.
The main issue, I believe, is the SetDestination line for the AI. The debug logs show correctly for even the second client if they reach the value of 50, however, the AI will only target the first client.
I am using PUN 2, which the first client is obviously the master client, but surely that shouldn't be the issue on why the AI isn't targeting anyone but the first client because the other things (the logs) in that code block show for other clients if they reach 50 or more.
Is there something I'm doing wrong here with my code? If you need more of an explanation please let me know.
Reposted this with hopefully better tags and responses.