Guest User

Untitled

a guest
Jan 10th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using Mirror;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class HookTest : NetworkBehaviour
  7. {
  8.  
  9.     [SyncVar(hook = nameof(SetMyField))]
  10.     bool _myField;
  11.  
  12.     int _runCount;
  13.  
  14.     void SetMyField(bool oldValue, bool newValue)
  15.     {
  16.         _runCount++;
  17.         Debug.Log("I got run: " + newValue);
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         if (base.isLocalPlayer)
  24.         {
  25.             if (Input.GetKeyDown(KeyCode.Y))
  26.             {
  27.                 _myField = !_myField;
  28.             }
  29.         }
  30.     }
  31.  
  32.     void OnGUI()
  33.     {
  34.         if (base.isLocalPlayer)
  35.             GUI.Label(new Rect(200, 200, 100, 100), "Local: " + _runCount.ToString());
  36.         else
  37.             GUI.Label(new Rect(250, 200, 100, 100), "Remote: " + _runCount.ToString());
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment