hello, I am making a multiplayer game using photon pun 2. when the player spawns in, if he is master client he is able to press a button called “start” when this button is pressed, all the players in the scene (only been tested with 2 players) are supposed to randomize a number over and over until one of them gets their number to equal 5, then that player instantiates a monster gameobject and deletes itself. (the player is now controlling the monster gameobject) however the problem is both players turn into the monster regardless of what happens. it always has a delay where both players are randomizing then one will turn, then the other. does anyone know why this is happening? here is the script on the starting gameobject that instantiates the monsters: (as you can see i am setting a static variable from another script (GameController) called “HasMonster” to true when a player turns into the monster. the player is only supposed to instantiate the monster if its variable lands on five and HasMonster is FALSE, which is why i set that variable to false after a player is turned into a monster.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerStart : MonoBehaviour
{
private bool ChangedAlready = false;
[SerializeField]
private bool IsMonster = false;
[SerializeField]
private int MonsterRandom = 0;
public bool GotKilled = false;
void MonsterChoose()
{
if (IsMonster == false && GameController.HasMonster == true)
{
NotMonster();
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("DestroyPlayer", RpcTarget.All);
}
if (GameController.HasMonster == false && EventManager.DidGameStart == true)
{
MonsterRandom = Random.Range(1, 100);
}
if (MonsterRandom == 5)
{
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("DestroyPlayer", RpcTarget.All);
IsMonster = true;
GameController.HasMonster = true;
MonsterDetect();
}
}
[PunRPC]
void DestroyPlayer()
{
Destroy(gameObject);
}
void NotMonster()
{
if(ChangedAlready == false)
{
PhotonNetwork.Instantiate("PlayerInstance", transform.position, transform.rotation);
Debug.Log("PLAYER");
ChangedAlready = true;
}
}
void MonsterDetect()
{
if(ChangedAlready == false)
{
PhotonNetwork.Instantiate("MonsterInstance", transform.position, transform.rotation);
Debug.Log("MONSTER");
GameController.HasMonster = true;
ChangedAlready = false;
}
}
void FixedUpdate()
{
MonsterChoose();
}
}