Having Trouble passing a reference

Options
I am developing a multiplayer game where the users can select different avatars so I am spawning a 2D Sprite and then parenting it to the playercontroller Obj. The sprite is supposed to contain a collider for a Raycast so the players can interact by clicking on each other. However, I tried to send the PlayerManager script to the child avatar as a reference in a script but the other players don't see the avatar as a child of the playercontroller obj nor does their versions of the avatar contain the PlayerManager in the reference.

I need to be able to send messages between PlayerManager scripts through their avatars. What is the best way to connect them? Should I attempt to add the collider to the PlayerManager script instead? I don't want to take that option unless I need to since this is the same PlayerManager script that exists in the previous Profile Creation screen.

Comments

  • I would recommend a few things:
    1) Use a sprite manager (which resides on all clients) that will allow you to associate an index or string with a particular sprite (we'll call it their avatar) that the players have selected for themselves (or you've selected for them).
    2) This index/string is sync'd across the network so any time it changes all users see updates to the each others' avatar.
    3) Your player prefab which shows the avatar should have an opacity 1 image overlay on top of the avatar sprite which is your clickable surface.
  • Thanks for the comments Kev, I managed to get something similar to work. I have a childed avatar that is able to talk to the parent to run the interactions and then I use Sprite swapping over the different avatar peices in order to get the custom avatar that I want.