Hey guys, I’ve been sitting here trying to figure this out for a bit of time.
I have two scripts.
Here is the one for Hider.
public class HiderCount : Photon.MonoBehaviour {
public static int HiderID = 0;
public enum PlayerType{
Seeker,
Hider
}
public PlayerType playerType;
// Use this for initialization
void Start () {
if (photonView.isMine) {
photonView.RPC ("HiderAdd", PhotonTargets.AllBufferedViaServer, null);
}
}
[RPC]
public void HiderAdd(){
HiderCount.HiderID += 1;
}
public void OnPhotonPlayerDisconnected (PhotonPlayer player) {
if (playerType == PlayerType.Hider) {
if (photonView.isMine) {
photonView.RPC ("HiderRemove", PhotonTargets.AllBufferedViaServer, null);
}
}
}
[RPC]
public void HiderRemove(){
HiderCount.HiderID -= 1;
}
}
Here is the one for Seeker.
public class SeekerCount : Photon.MonoBehaviour {
public static int SeekerID = 0;
public enum PlayerType{
Seeker,
Hider
}
public PlayerType playerType;
// Use this for initialization
void Start () {
if(photonView.isMine){
photonView.RPC ("SeekerAdd",PhotonTargets.AllBufferedViaServer,null);
}
}
[RPC]
public void SeekerAdd(){
SeekerCount.SeekerID += 1;
}
public void OnPhotonPlayerDisconnected (PhotonPlayer Player) {
if (playerType == PlayerType.Seeker) {
if (photonView.isMine) {
photonView.RPC ("SeekerRemove", PhotonTargets.AllBufferedViaServer, null);
}
}
}
[RPC]
public void SeekerRemove(){
SeekerCount.SeekerID -= 1;
}
}
Problem is, (JOINING GAME WORKS). - It properly loads the correct player count, but when players leave (VIA OnPhotonPlayerDisconnected(PhotonPlayer player).
It starts taking -1 from both teams.
can you spot a mistake in the scripts?
Yes I know the HiderCount.HiderID and SeekerCount.SeekerID are STATIC INTS.
I couldn’t think of any other way for this team stuff to work.
I even tried doing this (on a pause menu to Exit game) and it won’t even take -1 from any team if the player leaves.
public class ExitGame : Photon.MonoBehaviour {
public bool CanExit;
PhotonView MyView;
public enum PlayerType{
Seeker,
Hider
}
public PlayerType playerType;
public void GoToMain(){
if (photonView.isMine) {
if (playerType == PlayerType.Hider) {
if (photonView.isMine) {
photonView.RPC ("RemoveHider", PhotonTargets.AllBufferedViaServer, null);
}
}
if (playerType == PlayerType.Seeker) {
if (photonView.isMine) {
photonView.RPC ("RemoveSeeker", PhotonTargets.AllBufferedViaServer, null);
}
}
}
}
[RPC]
public void RemoveHider(){
Debug.Log ("Hide Quit The Game");
HiderCount.HiderID -=1;
CanExit = true;
if (CanExit) {
ExitNow ();
}
}
[RPC]
public void RemoveSeeker(){
Debug.Log ("Seeker Quit The Game");
SeekerCount.SeekerID -=1;
CanExit = true;
if (CanExit) {
ExitNow ();
}
}
public void ExitNow(){
Application.Quit();
}
}
PLEASE ANY HELP WOULD BE GREATLY APPRECIATED!