Skip to content
Snippets Groups Projects
Shopping.cs 3.63 KiB
Newer Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Shopping : MonoBehaviour
{
    private bool playerInRange;

    private bool isBuy=false;
    public Item sellItem = null;
    //public GameObject[] itemForSale = new GameObject[2];
    public List<GameObject> itemForSale = new List<GameObject>();
    public GameObject panelEbutton;
    public GameObject Ebutton;
    public GameObject textEbutton;

    public GameObject textEbuttonObject;



    // Start is called before the first frame update
    void Start()
    {
        panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
        
    }

    // Update is called once per frame
    void Update()
    {

        if(playerInRange)
        {
            switch (sellItem.id)
            {
                case 1:
                    textEbuttonObject.GetComponent<Text>().text="Chaussures de marche";
                    break;
                case 2:
                    textEbuttonObject.GetComponent<Text>().text="Bâton de marche";
                    break;
                case 3:
                    textEbuttonObject.GetComponent<Text>().text="Réchaud";
                    break;
                case 4:
                    textEbuttonObject.GetComponent<Text>().text="Tente";
                    break;
            }
        }

        if (Input.GetKeyDown(KeyCode.E) && playerInRange && sellItem && itemForSale.Count>0)
Raffael Di Pietro's avatar
Raffael Di Pietro committed
            PlayerNature.instance.LooseNature(25);
            switch (sellItem.id)
            {
                case 1:
                    Dialog.instance.setSituation("boutiqueChaussure");
                    break;
                case 2:
                    Dialog.instance.setSituation("boutiqueBaton");
                    break;
                case 3:
                    Dialog.instance.setSituation("boutiqueRechaud");
                    break;
                case 4:
                    Dialog.instance.setSituation("boutiqueTente");
            panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
            Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
            textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
            textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
            Inventory.instance.addItem(sellItem);
v.bloch's avatar
v.bloch committed
            Debug.Log(sellItem.name.ToString() + " a bien ete ajouté a l'inventaire");
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            playerInRange = true;
            if(isBuy==false)
            {
                panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
                Ebutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
                textEbutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
                textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(1f);
            }
            
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        playerInRange = false;
        panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
        textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);