100 lines
2.4 KiB
C#
100 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Menu_CreateItens : MonoBehaviour
|
|
{
|
|
public GameObject objModel;
|
|
public List<Sprite> sprites;
|
|
public CanvasGroup thisCG;
|
|
|
|
public IEnumerator CreateItens()
|
|
{
|
|
yield return new WaitForSeconds(.75f);
|
|
|
|
float horizontal = -200;
|
|
|
|
while (horizontal <= 200)
|
|
{
|
|
float vertical = -200;
|
|
|
|
while (vertical <= 200)
|
|
{
|
|
GameObject obj = Instantiate(objModel, transform);
|
|
|
|
float thishorizontal = horizontal;
|
|
thishorizontal += Random.Range(-16.0f, 16.1f);
|
|
|
|
float thisvertical = vertical;
|
|
thisvertical += Random.Range(-16.0f, 16.1f);
|
|
|
|
RectTransform rectObj = obj.GetComponent<RectTransform>();
|
|
rectObj.anchoredPosition =
|
|
new Vector2(thishorizontal, thisvertical);
|
|
|
|
Image img = obj.GetComponent<Image>();
|
|
img.sprite = sprites[Random.Range(0, sprites.Count)];
|
|
|
|
obj.GetComponent<Menu_Item>().rect = rectObj;
|
|
|
|
obj.transform.Rotate(new Vector3(0, 0, Random.Range(0, 360)));
|
|
|
|
vertical += 80;
|
|
|
|
StartCoroutine(ItemSpawnAnime(obj.transform));
|
|
|
|
yield return new WaitForSeconds(.025f);
|
|
}
|
|
|
|
horizontal += 80;
|
|
}
|
|
}
|
|
|
|
IEnumerator ItemSpawnAnime(Transform item)
|
|
{
|
|
float value = 0;
|
|
item.localScale = new Vector3(0, 0, 0);
|
|
while (item.localScale.x < 1)
|
|
{
|
|
value += Time.deltaTime * 2;
|
|
|
|
item.localScale = new Vector3(value, value, 1);
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
item.localScale = new Vector3(1, 1, 1);
|
|
}
|
|
|
|
private bool IsVisible()
|
|
{
|
|
if (Camera.main.ScreenToViewportPoint(transform.position).x < -0.1f || Camera.main.ScreenToViewportPoint(transform.position).x > 1.1f)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (!thisCG)
|
|
{
|
|
thisCG = GetComponent<CanvasGroup>();
|
|
}
|
|
if (IsVisible() && thisCG.alpha != 1)
|
|
{
|
|
thisCG.alpha = 1;
|
|
}
|
|
else if (!IsVisible() && thisCG.alpha != 0)
|
|
{
|
|
thisCG.alpha = 0;
|
|
}
|
|
}
|
|
}
|