PO/Assets/Scripts/IncidentSystem/IncidentSystem.cs

80 lines
2.0 KiB
C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class IncidentSystem : MonoBehaviour
{
public Text namePanel;
public string nameString;
public Node[] node;
public int _currentNode;
public bool ShowDialogue = true;
public Text textArea;
public Button[] answerButtons;
public Button closeIncident;
public void Start()
{
NewPhrase(0);
namePanel.text = nameString;
}
public void CloseTab()
{
Destroy(gameObject);
}
public void NewPhrase(int _phraseIndex)
{
if (ShowDialogue == false) CloseTab();
Player.main.ChangeHp(node[_phraseIndex].damage);
for (int i = 0; i < answerButtons.Length; i++)
{
answerButtons[i].gameObject.SetActive(false);
}
if (node[_phraseIndex].reward != null)
{
DataHolder.main.AddEquipmentToPlayerInventory(node[_phraseIndex].reward);
}
textArea.text = node[_phraseIndex].phrase;
if (node[_phraseIndex].PlayerAnswer.Length == 0)
{
closeIncident.gameObject.SetActive(true);
return;
}
int j = 0;
for (int i = 0; i < node[_phraseIndex].PlayerAnswer.Length; i++)
{
if (j >= answerButtons.Length) Debug.LogError("Warning! there are more answers than buttons");
answerButtons[j].gameObject.SetActive(true);
answerButtons[j].GetComponentInChildren<Text>().text = node[_phraseIndex].PlayerAnswer[i].text;
answerButtons[j].GetComponent<AnswerButton>().phaseIndex = node[_phraseIndex].PlayerAnswer[i].toNode;
j++;
}
}
}
[System.Serializable]
public class Node
{
[TextArea (3,20)]
public string phrase;
public Answer[] PlayerAnswer;
public GameObject reward;
[Header("Effects")]
public int damage;
}
[System.Serializable]
public class Answer
{
[TextArea(3, 10)]
public string text;
public int toNode;
}