103 lines
1.9 KiB
C#
103 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class PrizeChest : MonoBehaviour
|
|
{
|
|
|
|
public static PrizeChest Instance { get; private set; }
|
|
|
|
public GameObject glowSpot;
|
|
public GameObject confetti;
|
|
public GameObject itemSprite;
|
|
public GameObject chestLid;
|
|
|
|
private int[] itemOrder = new int[40];
|
|
|
|
|
|
|
|
public void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
glowSpot.transform.localScale = new Vector3(0, 0, 0);
|
|
glowSpot.SetActive(false);
|
|
confetti.SetActive(false);
|
|
itemSprite.transform.localScale = Vector3.zero;
|
|
itemSprite.SetActive(false);
|
|
chestLid.transform.DORotate(new Vector3(0, 0), 1.0f, RotateMode.Fast);
|
|
|
|
}
|
|
|
|
private void setItemOrder(int[] itemOrder)
|
|
{
|
|
this.itemOrder = itemOrder;
|
|
}
|
|
|
|
public void openChest(int[] itemOrder)
|
|
{
|
|
setItemOrder(itemOrder);
|
|
StartCoroutine(openChest());
|
|
}
|
|
|
|
public IEnumerator openChest()
|
|
{
|
|
chestLid.transform.DORotate(new Vector3(-50, 0), 1.0f, RotateMode.Fast);
|
|
|
|
//wait one second
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
glowSpot.SetActive(true);
|
|
itemSprite.SetActive(true);
|
|
itemSprite.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 0.7f);
|
|
|
|
float waitTime = 0.1f;
|
|
|
|
for (int i = 0; i < 40; i++)
|
|
{
|
|
|
|
int itemId = itemOrder[i];
|
|
//set the material of itemSprite
|
|
itemSprite.GetComponent<Renderer>().material.mainTexture = OnDemandLoader.Load<Texture>("Sprites/ItemSprites/" + itemId);
|
|
if (i >= 30)
|
|
{
|
|
waitTime += 0.05f;
|
|
}
|
|
if (i >= 35)
|
|
{
|
|
waitTime += 0.1f;
|
|
}
|
|
if (i == 39)
|
|
{
|
|
confetti.SetActive(true);
|
|
}
|
|
yield return new WaitForSeconds(waitTime);
|
|
}
|
|
|
|
yield return new WaitForSeconds(5.0f);
|
|
Start();
|
|
yield return null;
|
|
|
|
}
|
|
|
|
|
|
public void Update()
|
|
{
|
|
//when space key pressed
|
|
/*if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
|
|
//open the chest
|
|
StartCoroutine(openChest());
|
|
|
|
}*/
|
|
}
|
|
|
|
|
|
}
|