quests fixed
This commit is contained in:
@@ -11,9 +11,9 @@ public class npcScript : MonoBehaviour
|
||||
public GameObject textBtn;
|
||||
public TMP_Text npcText;
|
||||
// public string[] texts;
|
||||
public QuestScriptable [] questData;
|
||||
public int activeQuest;
|
||||
private int index;
|
||||
public QuestScriptable[] questData;
|
||||
public int activeQuest=0;
|
||||
public int questLineIndex;
|
||||
|
||||
//public GameObject questUI;
|
||||
|
||||
@@ -22,99 +22,132 @@ public class npcScript : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(isPlayerClose){
|
||||
// if(npcPanel.activeInHierarchy){
|
||||
// ResetTexts();
|
||||
// }else{
|
||||
// npcPanel.SetActive(true);
|
||||
// StartCoroutine(textLoad());
|
||||
// }
|
||||
if (isPlayerClose)
|
||||
{
|
||||
|
||||
}
|
||||
if(npcText.text == questData[activeQuest].questLines[index]){
|
||||
if (npcText.text == questData[activeQuest].questLines[questLineIndex])
|
||||
{
|
||||
textBtn.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ResetTexts(){
|
||||
npcPanel.SetActive(false);
|
||||
npcText.text = "";
|
||||
index = 0;
|
||||
}
|
||||
bool isLooping = false;
|
||||
IEnumerator textLoad(){
|
||||
isLooping = true;
|
||||
foreach(char letter in questData[activeQuest].questLines[index].ToCharArray()){
|
||||
bool isLoadingText = false;
|
||||
IEnumerator textLoad()
|
||||
{
|
||||
isLoadingText = true;
|
||||
foreach (char letter in questData[activeQuest].questLines[questLineIndex].ToCharArray())
|
||||
{
|
||||
npcText.text += letter;
|
||||
yield return new WaitForSecondsRealtime(textspeed);
|
||||
}
|
||||
isLooping=false;
|
||||
isLoadingText = false;
|
||||
}
|
||||
Coroutine textLoopAsync ;
|
||||
public void NextLine(){
|
||||
Coroutine textLoopAsync;
|
||||
public void NextLine()
|
||||
{
|
||||
textBtn.SetActive(false);
|
||||
if(index < questData[activeQuest].questLines.Length -1 ){
|
||||
index++;
|
||||
if (questLineIndex < questData[activeQuest].questLines.Length - 1)
|
||||
{
|
||||
questLineIndex++;
|
||||
npcText.text = "";
|
||||
LoadText();
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetTexts();
|
||||
|
||||
//Start quest
|
||||
// questUI.SetActive(true);
|
||||
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().QuestFunction(questData[activeQuest]);
|
||||
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().SetActiveQuest(questData[activeQuest]);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if(other.CompareTag("Player")){
|
||||
|
||||
if(other.transform == playerNetwork.localPlayerTransform){
|
||||
if(playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().currentQuest == questData[activeQuest]){
|
||||
void ResetTexts(){
|
||||
npcText.text = "";
|
||||
npcPanel.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
|
||||
if (other.transform == playerNetwork.localPlayerTransform)
|
||||
{
|
||||
playerNetwork pnet = playerNetwork.localPlayerTransform.GetComponent<playerNetwork>();
|
||||
if (pnet.currentQuest == questData[activeQuest]) //Already doing this quest
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(int i =0; i < questData.Length; i++){
|
||||
bool isFound = false;
|
||||
foreach(string questName in playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().completedQuests){
|
||||
if(questName == questData[i].name){
|
||||
isFound = true;
|
||||
|
||||
}
|
||||
|
||||
// for (int i = 0; i < questData.Length; i++)
|
||||
// {
|
||||
// bool isFound = false;
|
||||
// foreach (string questName in playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().completedQuests)
|
||||
// {
|
||||
// if (questName == questData[i].name)
|
||||
// {
|
||||
// isFound = true;
|
||||
|
||||
// }
|
||||
// }
|
||||
// if (!isFound)
|
||||
// {
|
||||
// activeQuest = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
if(pnet.completedQuests.Contains(questData[activeQuest].questName)){ //Set next quest if current one is completed
|
||||
for(int i=0; i < questData.Length; i++){
|
||||
if(pnet.completedQuests.Contains(questData[i].questName)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(!isFound){
|
||||
|
||||
activeQuest = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isPlayerClose = true;
|
||||
if(npcPanel.activeInHierarchy){
|
||||
ResetTexts();
|
||||
}else{
|
||||
npcPanel.SetActive(true);
|
||||
LoadText();
|
||||
}
|
||||
|
||||
isPlayerClose = true;
|
||||
if (npcPanel.activeInHierarchy)
|
||||
{
|
||||
ResetTexts();
|
||||
}
|
||||
else
|
||||
{
|
||||
questLineIndex=0;
|
||||
|
||||
npcPanel.SetActive(true);
|
||||
LoadText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LoadText(){
|
||||
void LoadText()
|
||||
{
|
||||
npcText.text = "";
|
||||
if(textLoopAsync!=null){
|
||||
if (textLoopAsync != null)
|
||||
{
|
||||
StopCoroutine(textLoopAsync);
|
||||
}
|
||||
textLoopAsync = StartCoroutine(textLoad());
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other) {
|
||||
if(other.CompareTag("Player")){
|
||||
if(other.transform == playerNetwork.localPlayerTransform){
|
||||
isPlayerClose = false;
|
||||
ResetTexts();
|
||||
}
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
if (other.transform == playerNetwork.localPlayerTransform)
|
||||
{
|
||||
isPlayerClose = false;
|
||||
ResetTexts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user