Advertisement
Jon50

Untitled

Feb 16th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. PLAYER MOVEMENT SCRIPT
  2.  
  3. public void CallNamesTagsRPC(string nickName, string tag, Vector3 playerColor)
  4.     {
  5.         /*=====> If the PhotonView is ours, as in the local player. <=====*/
  6.         if (PhotonView.IsMine)
  7.         {
  8.             /*=====> Set our properties AND tell everyone what our properties are. <=====*/
  9.             PhotonView.RPC("RPC_SetNamesAndTags", RpcTarget.All, nickName, tag, playerColor);
  10.         }
  11.     }
  12.  
  13.     [PunRPC]
  14.     void RPC_SetNamesAndTags(string nickName, string tag, Vector3 playerColor)
  15.     {
  16.         /*=====> NickName <=====*/
  17.         PhotonNetwork.NickName = nickName;
  18.         /*=====> The local player's GameObject name. You can see this in the Hierarchy. <=====*/
  19.         gameObject.name = nickName;
  20.         /*=====> Player tag. <=====*/
  21.         transform.tag = tag;
  22.  
  23.         transform.GetComponentInChildren<Renderer>().material.SetColor("_Color", new Color(playerColor.x, playerColor.y, playerColor.z));
  24.     }
  25.  
  26.  
  27. PLAYER SPAWN SCRIPT
  28.  
  29. if (players[i].IsMasterClient)
  30.  
  31.                 {
  32.  
  33.                     /*=====> Spawn over the network the Prefab located in - Assets\Resources\Avatar\PlayerAvatar.prefab - and pass (i) to the spawnPosition list and use its position and rotation. <=====*/
  34.  
  35.                     GameObject player = PhotonNetwork.Instantiate(Path.Combine("Avatar", "PlayerAvatar"), spawnPosition[i].position, spawnPosition[i].rotation, 0);
  36.  
  37.                     /*=====> To go over the network, use this example. Check bottom of PlayerMovement script. <=====*/
  38.  
  39.                     player.GetComponent<PlayerMovement>().CallNamesTagsRPC("Admin", "Player2", new Vector3(255, 0, 0)); // Set color to red.
  40.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement