Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Mirror;
- using UnityEngine;
- using Cinemachine;
- using UnityEngine.InputSystem;
- public class SimpleNetPlayer : NetworkBehaviour //you need this to do network stuff
- {
- [SerializeField] private int syncInt;
- [SyncVar(hook = nameof(OnSyncIntChanged))]
- private int syncedInt;
- [SyncVar]
- public float syncedFloat;
- [SyncVar]
- [HideInInspector]
- public string hiddenSyncedString;
- [Command]
- private void CmdDoSomething()
- {
- // Server-side logic executed when the client calls this command
- }
- [TargetRpc]
- private void TargetDoSomething(NetworkConnection target)
- {
- // Client-side logic executed when this RPC is targeted at the local client
- }
- [ClientRpc]
- private void RpcDoSomething()
- {
- // Client-side logic executed when this RPC is received on all clients
- }
- [Server]
- private void ServerOnlyMethod()
- {
- // Server-only logic executed when called on the server
- }
- [Client]
- private void ClientOnlyMethod()
- {
- // Client-only logic executed when called on the client
- }
- private void OnSyncIntChanged(int oldValue, int newValue)
- {
- // Logic executed when the syncedInt variable changes on clients
- }
- public void TeleportButton()
- {
- // chose a position and rotation here
- RpcTeleportationRequest(_position, _rotation);
- }
- [ClientRpc]
- public RpcTeleportationRequest(Vector3 _position, Quaternion _rotation)
- {
- NetworkClient.localPlayer.GetComponent<NetworkTransform>().RpcTeleport(_position, _rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement