Files
ihob/Assets/Scripts/EnemyLaserController.cs

33 lines
794 B
C#
Raw Permalink Normal View History

2026-02-21 17:04:05 -08:00
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;
}
}
}