How to change UI color for player viewing scoreboard?

Options

Hey All! So I have successfully implemented a scoreboard into my game, however, I would like for the local player's username to be displayed as a different color than the rest of the players in the room, similar to COD's scoreboard.

Below is the code that handles the ScoreboardItem

I tried this and the color of the text stayed white, but when I tried to change the if statement to if(!view.IsMine), it changed every one of the player's names to yellow, so I am a bit confused as to why that is happening and how I can achieve the goal of just changing the local player's username on the scoreboard to yellow. Any input will be appreciated. Thanks in advance!

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options

    A scoreboard is shared state and you can't solve this problem with a PhotonView.IsMine check because you don't have a networked score board per player.

    You should iterate over all players and per player check if it's the local player. The color for each entry depends on the current player being equal to the local one.

    Scores could be stored per player in Custom Player Properties. PUN 2 includes a prototyping script, called PunPlayerScores, which might help implementing this.

    MonoBehaviourPunCallbacks already provides a PhotonView instance (the one of this object), so you don't really need to find one in Awake() either.

Answers

  • tleylan
    Options

    I can only guess but from what you've written view.IsMine is never true. So you need to hunt down why that is .

    I assume you are calling Initialize() from some other class?

  • I assume you will have to add the PhotonView Component to the scoreboard to be able to make it work, or make it a child of one which does.

  • Tobias
    Tobias admin
    Answer ✓
    Options

    A scoreboard is shared state and you can't solve this problem with a PhotonView.IsMine check because you don't have a networked score board per player.

    You should iterate over all players and per player check if it's the local player. The color for each entry depends on the current player being equal to the local one.

    Scores could be stored per player in Custom Player Properties. PUN 2 includes a prototyping script, called PunPlayerScores, which might help implementing this.

    MonoBehaviourPunCallbacks already provides a PhotonView instance (the one of this object), so you don't really need to find one in Awake() either.

  • MrWalls
    Options

    I just checked back now and I appreciate everyone's input! I tried out what Tobias suggested and this solved it exactly! I am still grasping the concept of PhotonView but this made it make a lot more sense to me! Thank you!