Ln Go

Shop 본문

Unity/Quad Action

Shop

Ln Ro 2021. 6. 4. 02:24
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Shop : MonoBehaviour
{
    public RectTransform uiGroup;
    public Animator anim;

    public GameObject[] itemObj;
    public int[] itemPrice;
    public Transform[] itemPos;
    public string[] talkData;
    public Text talkText;


    Player enterPlayer;
    void Awake()
    {
        enterPlayer = null;
    }
    public void Enter(Player player)
    {
        enterPlayer = player;
        uiGroup.anchoredPosition = Vector3.zero;
    }

    public void Exit()
    {
        anim.SetTrigger("doHello");
        uiGroup.anchoredPosition = Vector3.down * 1000;
    }

    void Update()
    {
        EscEscape();
    }
    void EscEscape()
    {
        if (Input.GetKey(KeyCode.Escape))
            uiGroup.anchoredPosition = Vector3.down * 1000;
    }

    public void Buy(int index)
    {
        int price = itemPrice[index];
        if (price > enterPlayer.coin)
        {
            StopCoroutine(Talk());
            StartCoroutine(Talk());
            return;
        }

        enterPlayer.coin -= price;
        Vector3 ranVec = Vector3.right * Random.Range(-3, 3) + Vector3.forward * Random.Range(-3, 3);
        Instantiate(itemObj[index], itemPos[index].position + ranVec, itemPos[index].rotation);
    }

    IEnumerator Talk()
    {
        talkText.text = talkData[1];
        yield return new WaitForSeconds(2f);
        talkText.text = talkData[0];
    }
}

'Unity > Quad Action' 카테고리의 다른 글

Follow  (0) 2021.06.04
Item  (0) 2021.06.04
StartZone  (0) 2021.06.04
Orbit  (0) 2021.06.04
Missile  (0) 2021.06.04
Comments