Beginner Question: Player Owned GameObject

Hello,
I’m pretty sure that is a simple question, but I can’t find the solution by myself.

ok the scene is as following:

I got a scene with multiple players (already working thanks to Photon.PUN).
Now I want a script to change the opacity of the other players.
And I try to get each player GameObject in an array.

        void ChangePlayersOpacity ()
        {
            players = GameObject.FindGameObjectsWithTag("NetworkedPlayer");
            foreach (GameObject item in players)
            {
                //Do fancy color thing
            }
        }

now… how do I differentiate between my owned Gameobject and the other players. I do not want to change mine. (also some pointers on how to change the opacity would be nice too)

Hope you can help me

Hello @Papageilnsel

you have 2 different ways to do this…

  1. Add a field like “public GameObject myPlayer;” and set it in the inspector…

Now, change your function in this:

void ChangePlayersOpacity () {
    players = GameObject.FindGameObjectsWithTag("NetworkedPlayer");
    
    foreach (GameObject item in players) {
        if(item != this.myPlayer) { // if is not my player
            //Do fancy color thing
        }else{
            // here you can change YOUR player infos, or remove "else" if this is useless
        }
    }
}

  1. The second way, is based on your player script… I assume that your player has a script that other players don’t have… Assuming that this script’s name is “MyPlayerController.cs”

So, without add the field like the 1° method, simply change your code in this:

void ChangePlayersOpacity () {
    players = GameObject.FindGameObjectsWithTag("NetworkedPlayer");
    
    foreach (GameObject item in players) {
        if(!item.GetComponent<MyPlayerController>()) { // if is not my player, because don't have the controller script
            //Do fancy color thing
        }else{
            // here you can change YOUR player infos, or remove "else" if this is useless
        }
    }
}

Hope this can help you…