revival/game/Assets/Scripts/Artefacts/PickUpDisplay.cs

68 lines
1.9 KiB
C#

using System;
using Ktyl.Util;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class PickUpDisplay : MonoBehaviour
{
public bool paused => _paused;
[SerializeField] private static bool _paused;
[SerializeField] private GameObject artefactUI;
[SerializeField] private SerialInt nearbyArtefactID;
[SerializeField] private GameObject Player;
[SerializeField] private Text artefactText;
[SerializeField] private GameObject Artefacts;
[SerializeField] private InputSettings inputSettings;
[SerializeField] private DialogueSystem dialogue;
private Artefact chosenArtefact;
private static List<Artefact> completeList = new List<Artefact>();
private void Awake()
{
EventHandler.current.onArtefactUI += PopUpOn;
int i;
for(i=0; i<Artefacts.transform.childCount; i++)
{
completeList.Add(Artefacts.transform.GetChild(i).GetComponent<ArtefactControl>().data);
}
}
private void FixedUpdate()
{
foreach(Artefact arte in completeList)
{
if (nearbyArtefactID != -1 && arte.artefactID == nearbyArtefactID)
chosenArtefact = arte;
}
}
public void PopUpOn()
{
;
_paused = true;
artefactUI.SetActive(true);
Player.GetComponent<PlayerInput>().enabled = false;
artefactText.text = "You have unlocked " + chosenArtefact.Name + "!";
inputSettings.updateMode = (InputSettings.UpdateMode)1;
Time.timeScale = 0f;
}
public void PopUpOff()
{
_paused = false;
artefactUI.SetActive(false);
inputSettings.updateMode = (InputSettings.UpdateMode)2;
Player.GetComponent<PlayerInput>().enabled = true;
Time.timeScale = 1.0f;
dialogue.PlayLine(chosenArtefact.dialogueKey);
chosenArtefact = null;
}
}