Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Mirror;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HookTest : NetworkBehaviour
- {
- static int s_num;
- [SyncVar(hook = nameof(SetMyField))]
- bool _myField;
- int _runCount;
- int _myPlayerNumber;
- void Start()
- {
- _myPlayerNumber = s_num;
- s_num++;
- }
- void SetMyField(bool oldValue, bool newValue)
- {
- _runCount++;
- Debug.Log("I got run: " + newValue);
- }
- // Update is called once per frame
- void Update()
- {
- if (base.isLocalPlayer)
- {
- if (Input.GetKeyDown(KeyCode.Y))
- {
- _myField = !_myField;
- }
- }
- }
- void OnGUI()
- {
- if (base.isLocalPlayer)
- GUI.Label(new Rect(200, 200, 100, 100), "Local: " + _runCount.ToString());
- else
- GUI.Label(new Rect(300, 200 + _myPlayerNumber * 50, 100, 100), "Remote: " + _runCount.ToString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment