75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class HitboxSpawner : MonoBehaviour {
|
|
[SerializeField] public float spawnPeriod = 0f;
|
|
[SerializeField] public float activeTime = 0f;
|
|
[SerializeField] private float fadeTime = 0f;
|
|
|
|
[SerializeField] public GameObject hitboxToSpawn;
|
|
[SerializeField] public SpriteRenderer effectSpriteRenderer;
|
|
[SerializeField] public AudioSource audioSource;
|
|
|
|
private bool flip = false;
|
|
private SkillID skillToSpawn = SkillID.BASIC_ATTACK;
|
|
private int skillChoreographyIndex = 0;
|
|
|
|
|
|
private IEnumerator SpawnHitbox() {
|
|
GameObject hitbox = Instantiate(hitboxToSpawn);
|
|
HitboxController hbc = hitbox.GetComponent<HitboxController>();
|
|
SkillStats stats = PlayerMovement.GetSkillStats(skillToSpawn);
|
|
activeTime = stats.speedModifier;
|
|
hbc.Setup(stats.maxMonstersHit, stats.hitboxHitCounts[skillChoreographyIndex], stats.hitboxPowers[skillChoreographyIndex]);
|
|
hitbox.transform.position = transform.position;
|
|
hitbox.transform.localScale = transform.localScale;
|
|
hitbox.transform.SetParent(transform);
|
|
if (flip) {
|
|
hbc.flip = true;
|
|
}
|
|
Debug.Log("SpawnHitbox Tick " + skillToSpawn.ToString());
|
|
yield return new WaitForSeconds(spawnPeriod);
|
|
StartCoroutine("SpawnHitbox");
|
|
}
|
|
|
|
private void Die() {
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
public void Setup(bool flip, SkillID skillToSpawn, int skillChoreographyIndex) {
|
|
this.flip = flip;
|
|
this.skillToSpawn = skillToSpawn;
|
|
this.skillChoreographyIndex = skillChoreographyIndex;
|
|
|
|
if (flip) {
|
|
transform.localScale = new Vector3(-1f, 1f, 1f);
|
|
} else {
|
|
transform.localScale = new Vector3(1f, 1f, 1f);
|
|
}
|
|
|
|
if (audioSource != null) {
|
|
audioSource.Play();
|
|
}
|
|
|
|
StartCoroutine(SpawnHitbox());
|
|
Invoke("Die", activeTime);
|
|
Invoke("StartFadeOut", activeTime - fadeTime);
|
|
}
|
|
|
|
private void StartFadeOut() {
|
|
StartCoroutine("FadeOut");
|
|
}
|
|
|
|
IEnumerator FadeOut() {
|
|
for (float i = fadeTime; i >= 0; i -= Time.deltaTime) {
|
|
// TODO: Implement fade
|
|
// text.alpha = i / fadeTime;
|
|
effectSpriteRenderer.color = new Color(1f, 1f, 1f, i / fadeTime);
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
effectSpriteRenderer.color = new Color(1f, 1f, 1f, 0f);
|
|
}
|
|
}
|