mmorpg/Assets/Script/QuestAction.cs
2024-05-24 23:30:33 +05:30

44 lines
1.1 KiB
C#
Executable File

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class QuestAction : MonoBehaviour
{
public QuestScriptable questData;
bool isRegistered =false;
public UnityEvent OnComplete;
public bool isFinalAction = true;
private void OnTriggerEnter2D(Collider2D other) {
if(other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform){
OnComplete.Invoke();
if(isFinalAction){
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().CompleteQuest(questData);
}
gameObject.SetActive(false);
}
}
public void activate(){
gameObject.SetActive(true);
}
void Update()
{
if(playerNetwork.localPlayerTransform != null && !isRegistered){
Register();
}
}
void Register(){
playerNetwork.registerQuestAction(this);
isRegistered = true;
gameObject.SetActive(false);
}
}