33 lines
794 B
C#
33 lines
794 B
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class EnemyLaserController : MonoBehaviour
|
||
|
|
{
|
||
|
|
[SerializeField] List<Color> colors;
|
||
|
|
[SerializeField] float fadeDuration; // seconds per color
|
||
|
|
|
||
|
|
int colorIndex = 0;
|
||
|
|
SpriteRenderer sprite;
|
||
|
|
float fadeTime = 0;
|
||
|
|
|
||
|
|
// Start is called before the first frame update
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
sprite = GetComponent<SpriteRenderer>();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
sprite.color = Color.Lerp(colors[colorIndex], colors[(colorIndex+1)%colors.Count], fadeTime);
|
||
|
|
|
||
|
|
fadeTime += Time.deltaTime / fadeDuration;
|
||
|
|
|
||
|
|
if (fadeTime >= 1f) {
|
||
|
|
colorIndex = (colorIndex + 1) % colors.Count;
|
||
|
|
fadeTime = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|