void Start(){
killFeedUI = GameObject.Find ("KillFeed");
}
public void Die(){
GameObject[] players = GameObject.FindGameObjectsWithTag ("Player");
foreach(GameObject p in players){
p.GetComponent <PhotonView>().RPC("SendFeed", PhotonTargets.All, killersName);
}
PhotonNetwork.Destroy (gameObject);
}
[PunRPC]
public void SendFeed(string killer){
GameObject newFeed = GameObject.Instantiate (feedPrefab);
newFeed.transform.SetParent (killFeedUI.transform);
newFeed.transform.GetChild (0).GetComponent <Text>().text = (killer + " killed " + GetComponent <PhotonView>().owner.NickName);
newFeed.transform.localScale = new Vector3 (1, 1, 1);
}
In my code above, so bascially when I die, every player will instantiate a UI to their own canvas. Right now, when there’s only one player in the room, the SendFeed gets called to that one player(me), everything works fine. But if there’s 2 players, I get a nullreference on newFeed.transform.SetParent (killFeedUI.transform);
and the the UI gets instantiated infinately. Why is this happening? Everything works fine with one player, why are there problems with multiple?