Advertisement
Dieton

MyNotes

Jun 1st, 2023 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | Gaming | 0 0
  1. using Mirror;
  2. using UnityEngine;
  3. using Cinemachine;
  4. using UnityEngine.InputSystem;
  5.  
  6. public class SimpleNetPlayer : NetworkBehaviour //you need this to do network stuff
  7. {
  8.  [SerializeField] private int syncInt;
  9.  
  10.     [SyncVar(hook = nameof(OnSyncIntChanged))]
  11.     private int syncedInt;
  12.  
  13.     [SyncVar]
  14.     public float syncedFloat;
  15.  
  16.     [SyncVar]
  17.     [HideInInspector]
  18.     public string hiddenSyncedString;
  19.  
  20.     [Command]
  21.     private void CmdDoSomething()
  22.     {
  23.         // Server-side logic executed when the client calls this command
  24.     }
  25.  
  26.     [TargetRpc]
  27.     private void TargetDoSomething(NetworkConnection target)
  28.     {
  29.         // Client-side logic executed when this RPC is targeted at the local client
  30.     }
  31.  
  32.     [ClientRpc]
  33.     private void RpcDoSomething()
  34.     {
  35.         // Client-side logic executed when this RPC is received on all clients
  36.     }
  37.  
  38.     [Server]
  39.     private void ServerOnlyMethod()
  40.     {
  41.         // Server-only logic executed when called on the server
  42.     }
  43.  
  44.     [Client]
  45.     private void ClientOnlyMethod()
  46.     {
  47.         // Client-only logic executed when called on the client
  48.     }
  49.  
  50.     private void OnSyncIntChanged(int oldValue, int newValue)
  51.     {
  52.         // Logic executed when the syncedInt variable changes on clients
  53.     }
  54.  
  55. public void TeleportButton()
  56. {
  57. //  chose a position and rotation here
  58.     RpcTeleportationRequest(_position, _rotation);
  59. }
  60.  
  61. [ClientRpc]
  62. public RpcTeleportationRequest(Vector3 _position, Quaternion _rotation)
  63. {
  64.  NetworkClient.localPlayer.GetComponent<NetworkTransform>().RpcTeleport(_position, _rotation);
  65. }
  66.  
  67.  
  68. }
Tags: Unity mirror
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement