Skip to content
Snippets Groups Projects
clueObject.cs 1.45 KiB
Newer Older
Karim Ajouz's avatar
Karim Ajouz committed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Rhys Jacob's avatar
Rhys Jacob committed
using UnityEngine.UI;
Karim Ajouz's avatar
Karim Ajouz committed

public class clueObject : MonoBehaviour
{
Rhys Jacob's avatar
Rhys Jacob committed
    public bool allowInspection = false;
Karim Ajouz's avatar
Karim Ajouz committed
    bool searched = false;

    private EvidenceHandler e;
    private Notebook n;
    private CutsceneManager c;

    Evidence[] clues;
    // Start is called before the first frame update
    void Start()
    {
        clues = this.gameObject.GetComponents<Evidence>();
        e = FindObjectOfType<EvidenceHandler>();
        n = FindObjectOfType<Notebook>();
        c = FindObjectOfType<CutsceneManager>();
    }

    // Update is called once per frame
    void Update()
    {
Rhys Jacob's avatar
Rhys Jacob committed
        if(allowInspection)
        {
            this.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        } else
        {
            this.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        }

Karim Ajouz's avatar
Karim Ajouz committed
        if(allowInspection && Input.GetButtonDown("Inspect") & !searched)
        {
            for(int i = 0; i < clues.Length; i++)
            {
                e.foundClues.Add(clues[i]);
                n.AddClues(clues[i]);
            }

            searched = true;
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Character")
            allowInspection = true;
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "Character")
            allowInspection = false;
    }
}