| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SoulFollowEffect : MonoBehaviour
- {
- public float upSpeed;
- public bool notFind;
- [HideInInspector]
- public float angle;
- public int soulsNumber;
- public float rotateSpeed;
- public GameObject soul;
- public GameObject soul1;
- public ESpirits_Invisible eSpirits;
- [HideInInspector]
- public List<GameObject> soulsList = new List<GameObject>();
- public float distance;
- public bool isTransfiguration;
- public float KBoomSoulTime;
- public SoulBoom soulBoom;
- public bool isBooming;
- public bool isBoom;
- public int boomSoulNumber;
- public InvisibleSoulCollector soulCollector;
- public float boomScale;
- public Transform parent;
- private void Awake()
- {
- if (!isTransfiguration)
- {
- for (int i = 0; i < eSpirits.followNumber; i++)
- {
- GameObject newSoul = Instantiate(soul1.gameObject);
- newSoul.transform.parent = transform;
- newSoul.SetActive(false);
- soulsList.Add(newSoul);
- }
- }
- }
- private void Update()
- {
- angle += Time.deltaTime * rotateSpeed;
-
- if (angle >= 360)
- {
- angle -= 360;
- }
- transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
- if(isBooming)
- {
- KBoomSoulTime -= Time.deltaTime;
- if (KBoomSoulTime <= 0 && KBoomSoulTime > -soulBoom.boomTime)
- {
- if (!isBoom)
- {
- isBoom = true;
- Boom();
- }
-
- }
- if (KBoomSoulTime <= -soulBoom.boomTime)
- {
- for (int i = 0; i < boomSoulNumber; i++)
- {
- SoulChangeColor(i, false);
- }
- soulCollector.soulNumbers -= boomSoulNumber;
- ShowSouls(soulsNumber - boomSoulNumber);
- boomSoulNumber = 0;
- isBoom = false;
- isBooming = false;
- }
- }
-
- }
- public void DropSoul(int souNumber,bool changeUpSpeed = true)
- {
- float angle = 360f / souNumber;
- for (int i = 0; i < souNumber; i++)
- {
- GameObject soulObj = PoolManager.Instantiate(soul, transform.position);
- float targetRad = angle * i * Mathf.Deg2Rad;
- soulObj.transform.position = transform.position +
- new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
- Soul soulScript = soulObj.GetComponent<Soul>();
- if (changeUpSpeed)
- {
- soulScript.Spirits_Invisible_NotFind = notFind;
- soulScript.upSpeed = upSpeed;
- }
- soulScript.Burst(Vector3.zero);
- }
-
- }
- public void Boom()
- {
- GameObject boomSoul = Instantiate(soulBoom.gameObject);
- boomSoul.transform.position = transform.position;
- boomSoul.SetActive(true);
- }
- public void ShowSouls(int newNumber)
- {
- if(soulsList.Count < newNumber)
- {
- GameObject newSoul = Instantiate(soul1.gameObject);
- newSoul.transform.parent = transform;
- newSoul.SetActive(false);
- soulsList.Add(newSoul);
- }
- if(newNumber == 0)
- {
- for(int i = 0;i< soulsList.Count; i++)
- {
- soulsList[i].gameObject.SetActive(false);
- }
- }
- if (newNumber > soulsNumber)
- {
- for(int i = soulsNumber; i < newNumber; i++)
- {
- soulsList[i].gameObject.SetActive(true);
- }
-
- float angle = 360f / newNumber;
- for (int i = 0; i < newNumber; i++)
- {
- float targetRad = angle * i * Mathf.Deg2Rad;
- soulsList[i].transform.localPosition =
- new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
- }
- }
- if(newNumber < soulsNumber)
- {
- for(int i = newNumber;i<soulsNumber;i++)
- {
- soulsList[i].gameObject.SetActive(false);
- }
-
- float angle = 360f / newNumber;
- for (int i = 0; i < newNumber; i++)
- {
- float targetRad = angle * i * Mathf.Deg2Rad;
- soulsList[i].transform.localPosition =
- new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
- }
- }
- soulsNumber = newNumber;
- }
- public void SoulChangeColor(int id,bool isRed)
- {
- if (isRed)
- {
- soulsList[id].transform.GetChild(0).gameObject.SetActive(false);
- soulsList[id].transform.GetChild(1).gameObject.SetActive(true);
- }
- else
- {
- soulsList[id].transform.GetChild(1).gameObject.SetActive(false);
- soulsList[id].transform.GetChild(0).gameObject.SetActive(true);
- }
- }
- }
|