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

60 lines
1.6 KiB
C#
Raw Normal View History

2021-03-01 19:09:21 +01:00
using Ktyl.Util;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2021-03-02 17:33:31 +01:00
using UnityEngine.InputSystem;
using UnityEngine.UI;
2021-03-01 19:09:21 +01:00
public class PickUpDisplay : MonoBehaviour
{
public bool paused => _paused;
[SerializeField] private static bool _paused;
[SerializeField] private GameObject artefactUI;
[SerializeField] private SerialInt nearbyArtefactID;
2021-03-02 17:33:31 +01:00
[SerializeField] private GameObject Player;
[SerializeField] private Text artefactText;
[SerializeField] private GameObject Artefacts;
2021-03-01 19:09:21 +01:00
2021-03-02 17:33:31 +01:00
private Artefact chosenArtefact;
private static List<Artefact> completeList = new List<Artefact>();
private void Awake()
2021-03-01 19:09:21 +01:00
{
EventHandler.current.onArtefactUI += PopUpOn;
2021-03-02 17:33:31 +01:00
int i;
for(i=0; i<Artefacts.transform.childCount; i++)
{
completeList.Add(Artefacts.transform.GetChild(i).GetComponent<ArtefactControl>().data);
}
2021-03-01 19:09:21 +01:00
}
2021-03-02 17:33:31 +01:00
private void FixedUpdate()
{
foreach(Artefact arte in completeList)
{
if (nearbyArtefactID != -1 && arte.artefactID == nearbyArtefactID)
chosenArtefact = arte;
}
}
2021-03-01 19:09:21 +01:00
public void PopUpOn()
{
_paused = true;
artefactUI.SetActive(true);
2021-03-02 17:33:31 +01:00
Player.GetComponent<PlayerInput>().enabled = false;
artefactText.text = "You have unlocked " + chosenArtefact.Name + "!";
2021-03-02 18:10:12 +01:00
Time.timeScale = 0f;
2021-03-01 19:09:21 +01:00
}
public void PopUpOff()
{
_paused = false;
artefactUI.SetActive(false);
2021-03-02 17:33:31 +01:00
Player.GetComponent<PlayerInput>().enabled = true;
2021-03-02 18:10:12 +01:00
Time.timeScale = 1.0f;
2021-03-01 19:09:21 +01:00
}
}