Showing GameObject for A Single Player

I was wondering if if was possible to show a gameobject on the scene for a single player. My intention is to instantiate and display this gameObject in the scene for Player 1 and not show it for Player 2, 3 etc. Afterwards, for Player 2, instantiate the gameObject (with different properties from the first gameObject) again but not show if for Player 1, 3 etc.

If I had code like this,
    foreach (Player player in PhotonNetwork.PlayerList) {
        GameObject card = PhotonNetwork.Instantiate(this.redCardPrefab.name, transform.position, transform.rotation);
        redCard.GetComponent<PhotonView>().TransferOwnership(player);
            if (!redCard.GetComponent<PhotonView>().IsMine) {
                PhotonNetwork.Destroy(redCard);
            }
    }

When run with something similar to above code, Player 1 sees his gameObject and Player 2's gameObject and Player 2 can see Player 1's gameObject and his gameObject in the scene.

Is there any work around to solving this kind of concept? I assumed I would not need an RPC but I could be wrong.

Any help would greatly be appreciated.

Comments

  • Why not just use normal Instantiate? This will only create the object for the local player, the server sends an RPC to each client when they need to spawn the object and with what properties.
  • hlin37hlin37
    edited July 4
    But how would I make it so that the gameObject appears for Player 1's screen but not on Player 2 or Player 3's screen? I'm assuming I would have to use an RPC but not sure on which methods I could use. I've tried using Destroy and PhotonNetwork.Destroy() and tried gameObject.SetActive(false)

    Below is my code right now. Currently when I run two clients, both clients see four cards when I want each client to see two cards.
    private PhotonView objectOwner;
    private GameObject card;
    
            for (int i = 0; i < 2; i++) {
                foreach (Player player in PhotonNetwork.PlayerList) {
                   card = Instantiate(cardPrefab, transform.position, transform.rotation);
                    objectOwner = whiteCard.GetComponent<PhotonView>();
                    PhotonNetwork.AllocateViewID(objectOwner);
                    objectOwner.TransferOwnership(player);
                }
            }
    
    If I need to use an RPC, what methods would I have to use?

    Any help would be appreciated.
Sign In or Register to comment.