68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CollectEffect : MonoBehaviour
|
|
{
|
|
public static CollectEffect instance;
|
|
public Transform solarPanel;
|
|
public Transform goldMine;
|
|
public RectTransform goldStats, metalStats;
|
|
public Sprite energyIcon;
|
|
public Sprite goldsIcon;
|
|
|
|
void Awake(){
|
|
instance=this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void Show( CollectablesData.ResourceType type){
|
|
gameObject.SetActive(true);
|
|
switch(type){
|
|
case CollectablesData.ResourceType.Gold:
|
|
foreach(Image image in transform.GetComponentsInChildren<Image>(true)){
|
|
image.sprite = goldsIcon;
|
|
}
|
|
StartCoroutine(startEffect(Camera.main.WorldToScreenPoint(goldMine.position), goldStats.position));
|
|
|
|
break;
|
|
case CollectablesData.ResourceType.Metal:
|
|
foreach(Image image in transform.GetComponentsInChildren<Image>(true)){
|
|
image.sprite = energyIcon;
|
|
}
|
|
StartCoroutine(startEffect(Camera.main.WorldToScreenPoint(solarPanel.position), metalStats.position));
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
[Header("Animation tweaks")]
|
|
public int steps = 500;
|
|
public int offset = 10;
|
|
IEnumerator startEffect(Vector3 start, Vector3 stop){
|
|
Vector3 diff = stop - start;
|
|
for(int i=0; i < transform.childCount; i++){
|
|
StartCoroutine(travel(transform.GetChild(i), start,stop));
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
}
|
|
|
|
IEnumerator travel(Transform item, Vector3 start, Vector3 stop){
|
|
Vector3 diff = stop - start;
|
|
item.gameObject.SetActive(true);
|
|
|
|
for(int i =0; i < steps; i++){
|
|
item.position = start + (diff * ((float)i/(float)steps));
|
|
item.localScale = Vector3.one * (1-(float)(Mathf.Abs(((float)steps/2f) - i)) / ((float)steps / 2f));
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
}
|