53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class IntroButtonPulse : MonoBehaviour
|
|
{
|
|
[Header("Scale Pulse")]
|
|
[SerializeField] private float scaleAmount = 0.06f;
|
|
[SerializeField] private float pulseSpeed = 2.0f;
|
|
|
|
[Header("Color Pulse")]
|
|
[SerializeField] private bool useColorPulse = true;
|
|
[SerializeField] private Image targetImage;
|
|
[SerializeField] private Color normalColor = Color.white;
|
|
[SerializeField] private Color glowColor = new Color(1f, 0.85f, 0.95f, 1f);
|
|
|
|
private Vector3 startScale;
|
|
|
|
private void Awake()
|
|
{
|
|
startScale = transform.localScale;
|
|
|
|
if (targetImage == null)
|
|
{
|
|
targetImage = GetComponent<Image>();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateScalePulse();
|
|
UpdateColorPulse();
|
|
}
|
|
|
|
private void UpdateScalePulse()
|
|
{
|
|
float t = (Mathf.Sin(Time.time * pulseSpeed) + 1f) * 0.5f;
|
|
float scale = 1f + t * scaleAmount;
|
|
|
|
transform.localScale = startScale * scale;
|
|
}
|
|
|
|
private void UpdateColorPulse()
|
|
{
|
|
if (!useColorPulse)
|
|
return;
|
|
|
|
if (targetImage == null)
|
|
return;
|
|
|
|
float t = (Mathf.Sin(Time.time * pulseSpeed) + 1f) * 0.5f;
|
|
targetImage.color = Color.Lerp(normalColor, glowColor, t);
|
|
}
|
|
} |