I want to avoid mixing Canvas from other players in Unity Photon.

Asked 1 years ago, Updated 1 years ago, 45 views

I'm trying to create a wolf-like online game using Unity's Photon.
It was good until I gave each player a position, but if I put it on each player's screen, the position will not be displayed correctly.
There are no errors.

public PhotoView photoView;
public GameObject jobUI;

if(!photoView.isMine){
   jobUI.SetActive(false);
} else{
   jobUI.SetActive(true);
}

public IEnumerator JobOnGUI (GameObject player)
{
    jobUI.SetActive(true);
    yield return new WaitForSeconds (5f);
    Text jobText=jobUI.transform.Find("JobText").GetComponent<Text>();
    jobText.text=player.GetComponent<PlayerController>().GetJob().ToString();
}

I'm a beginner, so the format is quite messy.

Instantiate the UI for position display in the child element of the prefabricated player with PhotonView.
I put the player in the photoView and the jobUI put the panel in the Canvas child element.The child element of the panel has JobText.
The text in JobText contains an enumeration of the PlayerController (script for player control) positions.
GameManager has set up a position (which is also functioning correctly) and is calling this routine.

Each player's jobText contains the correct position, but the actual position displayed is different.

c# unity3d

2022-09-30 15:50

1 Answers

Instantiate the UI for positioning in the child element of the player prefabricated with PhotonView.

This Instantiate is the PhotonNetwork.Instantiate method, right?In that case, the "UI for position indication" will appear in everyone's UI.

Of course, I would like to create a prefabricated player for all clients, but I think I should only generate the UI myself.

In other words, only the UI part should be prefabricated and the UI prefabricated (Object.Instantiate) only if the Player satisfies PhotonView.isMine==true.At this time, the prefabricated UI does not require the PhotonView component.


2022-09-30 15:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.