83 lines
2.8 KiB
C#
83 lines
2.8 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 Animator GoldAnim, MetalAnim;
|
|
public Transform GoldEffect, MetalEffect;
|
|
public float EffectScale =1;
|
|
|
|
void Awake(){
|
|
instance=this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
public void Show(CollectablesData.ResourceType type, int amount){
|
|
if(type == CollectablesData.ResourceType.Gold){
|
|
GoldEffect.GetComponent<ParticleSystem>().maxParticles = (int)Mathf.Clamp(amount * EffectScale, 5, 100);
|
|
StartCoroutine(PlayAnimation(GoldAnim, GoldEffect));
|
|
}else{
|
|
MetalEffect.GetComponent<ParticleSystem>().maxParticles = (int)Mathf.Clamp(amount * EffectScale, 5, 100);
|
|
|
|
StartCoroutine(PlayAnimation(MetalAnim,MetalEffect));
|
|
}
|
|
}
|
|
|
|
IEnumerator PlayAnimation(Animator anim, Transform target){
|
|
target.gameObject.SetActive(false);
|
|
anim.Play("CollectAnim");
|
|
yield return new WaitForSeconds(0.05f);
|
|
target.gameObject.SetActive(true);
|
|
while(anim.GetCurrentAnimatorStateInfo(0).IsName("CollectAnim")){
|
|
target.position = anim.transform.position;
|
|
yield return null;
|
|
}
|
|
|
|
}
|
|
|
|
// IEnumerator startEffect(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);
|
|
// }
|
|
// [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);
|
|
// }
|
|
}
|