chip-game/Assets/Scripts/RGB_FOntAsset.cs

58 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class RGB_FOntAsset : MonoBehaviour
{
public Material material;
public float speed = 1f;
[Header("Масштабирование")]
public float min = 1.2f;
public float max = 2f;
private float mid;
private float half;
public float scaleSpeed = 7;
[Header("Вращение")]
public float rotateSpeed = 10;
public float angularAmpliude = 5;
private float hue = 0f;
private void OnEnable()
{
mid = 0.5f * (min + max);
half = 0.5f * (max - min);
}
private void Update()
{
if (material != null)
{
// Изменяем оттенок (hue) от 0 до 1
hue += Time.deltaTime * speed;
hue %= 1f; // Ограничиваем от 0 до 1
// Преобразуем HSV в RGB
Color color = Color.HSVToRGB(hue, 1f, 1f);
material.SetColor(ShaderUtilities.ID_GlowColor, color);
}
float t = Time.time * scaleSpeed;
float s = mid + half * Mathf.Sin(t);
transform.localScale = Vector3.one * s;
t = Time.time * rotateSpeed;
float zAngle = angularAmpliude * Mathf.Sin(t);
transform.rotation = Quaternion.Euler(0, 0, zAngle);
}
}