PushButton.cs 837 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mirror;
  5. using UnityEngine.Events;
  6. public class PushButton : NetworkBehaviour
  7. {
  8. public UnityEvent OnServerActivate;
  9. public UnityEvent OnActivate;
  10. void OnTriggerEnter2D(Collider2D other) {
  11. Debug.Log(other.name + " Entered");
  12. if(!isServer){
  13. return;
  14. }
  15. if(other.GetComponent<NetPlayer>()!=null){
  16. //Player entered
  17. Debug.Log($"{other.name} Invoked server push button");
  18. OnServerActivate.Invoke();
  19. OnActivate.Invoke();
  20. RpcActivate();
  21. gameObject.SetActive(false);
  22. }
  23. }
  24. [ClientRpc]
  25. void RpcActivate(){
  26. OnActivate.Invoke();
  27. gameObject.SetActive(false);
  28. }
  29. }