66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
//TODO: make this object pool compatible
|
|||
|
|
|||
|
namespace Lemon.GenericLib.VFX
|
|||
|
{
|
|||
|
public class GhostManager : MonoBehaviour
|
|||
|
{
|
|||
|
public float ghostInterval = 0.1f;
|
|||
|
public float ghostLifeTime = 0.5f;
|
|||
|
private float currentInterval = 0;
|
|||
|
public GameObject ghost;
|
|||
|
public bool createGhost = false;
|
|||
|
public bool recolourGhost;
|
|||
|
public Color ghostColor;
|
|||
|
|
|||
|
private SpriteRenderer sr;
|
|||
|
|
|||
|
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
sr = GetComponent<SpriteRenderer>();
|
|||
|
currentInterval = 0;
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if (currentInterval >= ghostInterval)
|
|||
|
{
|
|||
|
if (!createGhost) return;
|
|||
|
GameObject currentGhost = Instantiate(ghost, transform.position, transform.rotation);
|
|||
|
currentGhost.transform.localScale = transform.localScale;
|
|||
|
currentGhost.GetComponent<SpriteRenderer>().sprite = sr.sprite;
|
|||
|
|
|||
|
if (recolourGhost)
|
|||
|
{
|
|||
|
currentGhost.GetComponent<SpriteRenderer>().color = ghostColor;
|
|||
|
}
|
|||
|
|
|||
|
Destroy(currentGhost, ghostLifeTime);
|
|||
|
currentInterval = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
currentInterval += Time.deltaTime;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void CreateGhostTemp(float time)
|
|||
|
{
|
|||
|
StartCoroutine(CreateGhostTempRoutine(time));
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator CreateGhostTempRoutine(float time)
|
|||
|
{
|
|||
|
createGhost = true;
|
|||
|
yield return new WaitForSeconds(time);
|
|||
|
createGhost = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|