Hmm...
That will be hard for me to debug this since it's a custom modification and there are a few things that concern me about the piece of code that you show me,
instead of trying to figure out what is wrong in your code and I'll provide a better approach for what you are trying to do using the IGameMode interface which provide many useful events.
So basically, you want to detect when they're not more players of Team1 alive or the if match time ends, Team2 win, so:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using Photon.Realtime;
using UnityEngine;
using Photon.Pun;
public class InfectedMode : MonoBehaviour, IGameMode
{
/// <summary>
///
/// </summary>
void Awake()
{
if (!PhotonNetwork.IsConnected)
return;
Initialize();
}
/// <summary>
///
/// </summary>
void OnDisable()
{
bl_PhotonCallbacks.PlayerPropertiesUpdate -= OnPlayerPropertiesUpdate;
}
#region Interface
public bool isLocalPlayerWinner
{
get
{
return "No defined";
}
}
public void Initialize()
{
//check if this is the game mode of this room
if (bl_GameManager.Instance.IsGameMode(GameMode.Infected, this))
{
bl_GameManager.Instance.SetGameState(MatchState.Starting);
bl_PhotonCallbacks.PlayerPropertiesUpdate += OnPlayerPropertiesUpdate;
//show your game mode specif objects
}
else
{
//hide the game mode objects.
}
}
/// <summary>
/// This will be called when the round time ends.
/// </summary>
/// <param name="gameOver"></param>
public void OnFinishTime(bool gameOver)
{
if (PhotonNetwork.OfflineMode) return;
if(Team1Alive > 0)
{
bl_InfectedUI.Instance.WinValue = true;
bl_InfectedUI.Instance.WinUI();
WinnerTeam = Team.Team1;
}
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="changedProps"></param>
public void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
{
//When someone die
if (changedProps.ContainsKey(PropertiesKeys.KillsKey))
{
CheckScore();
}
}
/// <summary>
///
/// </summary>
void CheckScore()
{
if (Team1Alive <= 0)
{
bl_InfectedUI.Instance.WinValue = false;
bl_InfectedUI.Instance.WinUI();
WinnerTeam = Team.Team2;
}
}
public void OnRoomPropertiesUpdate(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
{
}
public void OnLocalPlayerDeath()
{
}
public void OnLocalPlayerKill()
{
}
public void OnLocalPoint(int points, Team teamToAddPoint)
{
CheckScore();
}
public void OnOtherPlayerEnter(Player newPlayer)
{
}
public void OnOtherPlayerLeave(Player otherPlayer)
{
}
#endregion
}
I think the code explain itself, you can use it as reference and merge with your code,
I hope this helps.