12345678910111213141516171819202122232425262728293031323334 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Mirror;
- using UnityEngine.Events;
- public class PushButton : NetworkBehaviour
- {
- public UnityEvent OnServerActivate;
- public UnityEvent OnActivate;
- void OnTriggerEnter2D(Collider2D other) {
- Debug.Log(other.name + " Entered");
- if(!isServer){
- return;
- }
- if(other.GetComponent<NetPlayer>()!=null){
- //Player entered
- Debug.Log($"{other.name} Invoked server push button");
- OnServerActivate.Invoke();
- OnActivate.Invoke();
- RpcActivate();
- gameObject.SetActive(false);
- }
- }
- [ClientRpc]
- void RpcActivate(){
- OnActivate.Invoke();
- gameObject.SetActive(false);
- }
- }
|