Newer
Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shopping : MonoBehaviour
{
private bool playerInRange;
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)
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);
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);