QuestAction.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. public class QuestAction : MonoBehaviour
  6. {
  7. public QuestScriptable questData;
  8. bool isRegistered =false;
  9. public UnityEvent OnComplete;
  10. public bool isFinalAction = true;
  11. private void OnTriggerEnter2D(Collider2D other) {
  12. if(other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform){
  13. OnComplete.Invoke();
  14. if(isFinalAction){
  15. playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().CompleteQuest(questData);
  16. }
  17. gameObject.SetActive(false);
  18. }
  19. }
  20. public void activate(){
  21. gameObject.SetActive(true);
  22. }
  23. void Update()
  24. {
  25. if(playerNetwork.localPlayerTransform != null && !isRegistered){
  26. Register();
  27. }
  28. }
  29. void Register(){
  30. playerNetwork.registerQuestAction(this);
  31. isRegistered = true;
  32. gameObject.SetActive(false);
  33. }
  34. }