- Home /
hi i need help with code
so i have my game and these are the 2 relevant pieces of code to the problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class impostorCheckScript : MonoBehaviourPunCallbacks
{
bool roleSet = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
photonView.RPC("impostorCheckScriptMethod", RpcTarget.All, readyNotReadyScript.TaggedPlayerNum, readyNotReadyScript.TaggedPlayerNum2);
}
[PunRPC]
void impostorCheckScriptMethod(Player player1, Player player2)
{
if (PhotonNetwork.LocalPlayer == player1 || PhotonNetwork.LocalPlayer == player2 && roleSet == false)
{
Debug.Log("set to impostor");
roleSet = true;
GetComponent<impostorScript>().enabled = true;
}
else if (PhotonNetwork.LocalPlayer != player1 && PhotonNetwork.LocalPlayer != player2 && roleSet == false)
{
Debug.Log("set to crewnate");
roleSet = true;
}
}
}
[PunRPC]
void tagImpostorMethod(Player player1, Player player2)
{
if (PhotonNetwork.LocalPlayer == player1 || PhotonNetwork.LocalPlayer == player2 && roleSet == false)
{
this.gameObject.tag = "impostor";
gameObject.layer = 1 << 1;
roleSet = true;
Debug.Log("tagging Impostors");
}
else if (PhotonNetwork.LocalPlayer != player1 && PhotonNetwork.LocalPlayer != player2)
{
Debug.Log("sasdwadwasd wald mjwaoikn dlo;kawnkl; wnaet to crewnate");
roleSet = true;
}
}
and my problem is that each player's perspective is different. what i mean is that for all the "crewnate" players all OTHER players are ALSO crewnates... including the IMPOSTORS! and of course, the other way around also applies meaning all impostors see the other players as impostors, which is not good, since i want those 2 roles to be synced. how can i sync this code so that each client knows who is what.
Answer by Zubzuke · Nov 14, 2020 at 05:40 PM
You can only use layers 8+, you are trying to use layer 2 (because 1<<1 == 2):
https://docs.unity3d.com/ScriptReference/GameObject-layer.html
no thats not even my problem. i mean i tried in case it conflicts or its a bug or whatever but it sitll does the same result.