Skip to content

Commit

Permalink
fix: fixing errors in tanks sample
Browse files Browse the repository at this point in the history
- fixing use of world
- adding checks so client code only runs on client
  • Loading branch information
James-Frowen committed May 30, 2021
1 parent a9f8319 commit ed99d05
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Assets/Mirage/Samples~/Tanks/Scripts/TankGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ public class TankGameManager : MonoBehaviour
public List<Tank> players = new List<Tank>();
public NetworkManager NetworkManager;


void Update()
{
if (NetworkManager.IsNetworkActive)
{
GameReadyCheck();
GameOverCheck();

if (LocalPlayer == null)
{
FindLocalTank();
}
else
if (NetworkManager.Client.Active)
{
ShowReadyMenu();
UpdateStats();
if (LocalPlayer == null)
{
FindLocalTank();
}
else
{
ShowReadyMenu();
UpdateStats();
}
}
}
else
Expand Down Expand Up @@ -84,7 +86,8 @@ void GameReadyCheck()

void CheckPlayersNotInList()
{
foreach (NetworkIdentity identity in NetworkManager.Client.World.SpawnedIdentities)
NetworkWorld world = NetworkManager.Server.Active ? NetworkManager.Server.World : NetworkManager.Client.World;
foreach (NetworkIdentity identity in world.SpawnedIdentities)
{
Tank comp = identity.GetComponent<Tank>();
if (comp != null && !players.Contains(comp))
Expand Down Expand Up @@ -145,11 +148,13 @@ int GetAlivePlayerCount()

void FindLocalTank()
{
//Check to see if the player is loaded in yet
if (NetworkManager.Client.Player == null)
INetworkPlayer player = NetworkManager.Client.Player;

// Check to see if the player object is loaded in yet
if (player.Identity == null)
return;

LocalPlayer = NetworkManager.Client.Player.Identity.GetComponent<Tank>();
LocalPlayer = player.Identity.GetComponent<Tank>();
}

void UpdateStats()
Expand Down

0 comments on commit ed99d05

Please sign in to comment.