Setting CustomProperty for each player

Options

Hello,

I'm learning with Unity and Photon. I was following the Blackthornprod tutorials (https://www.youtube.com/watch?v=D28Drg9MCi4&t), but with my own twist (that may be causing the problems).

I'm stuck on the step of transferring players to a common scene.

This is my script for spawning the players in the scene:

It's really similar to the one in the Blackthornprod video (25:05), I just added another custom property to the player - index, because I don't want the spawnpoints to be random. Plus I want to have something like scoreboard in the game, each score will be linked to the player via the ID (if there's a better way to do it, I would be glad to hear it!). When I get here, the index is not set - the message is null. The playerAvatars transform to the game perfectly, each player has a different colour how I intended. So I guess, the problem must be in setting the index. I tried to connect this functionality with the play game button (so leaving and rejoining a room won't ruin the IDs in any way).

This is the method:

I guess, the problem is how I access the players. I tried it the commented way (not using the newPlayerItem), but that did not work either.

Here's the SetPlayerIndex method, which is located in the PlayerItem Class (which includes all the methods with setting the avatar property, which works):

Here, the log message is without a flaw, the number it prints is correct. Again, I tried it the commnted way, but again it did not help.


If anything is unclear let me know!

Thanks for your time.

Answers

  • Kruzby
    Options

    Ok, I guess I figured it out. Tried using PlayerNumbering extension, but didn't manage to set it up. Eventually I realzied how to use ActorId. The game is still really broken. I can see the two players only in one client (there's only one player in the second client). Plus, in the client, where I can see both, when I try to move, I move with objects (players).

    If anyone experienced something similar, I would appreciate any advice!

    But I'm out of brain juice for today.

  • Tobias
    Tobias admin
    edited January 2022
    Options

    I would recommend following the PUN Basics Tutorial once, before you approach the twist in your project.

    It should lay out the basics and if there are questions open, you are already on the docs pages for PUN and can continue to read about custom properties, etc.