본문 바로가기
개발/C#

유니티 C# 이미지 그라데이션 효과 주기 Image Gradient

by SPNK 2023. 8. 7.
반응형
  • 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ImageEffect : MonoBehaviour
{
    public Gradient gradient;

    [Range(0,5)]
    public float time = 1; //정해진 시간마다 주기적으로 반복

    float gradientWaveTime;
    float curXNormalized;

    private Image image;

    private void Awake()
    {
        image = GetComponent<Image>();

    }

    private void Update()
    {
        gradientWaveTime += Time.deltaTime;

        curXNormalized = Mathf.PingPong(gradientWaveTime, time);

        Color c = gradient.Evaluate(curXNormalized);
        image.color = new Color(c.r, c.g, c.b);
    }
}
반응형

댓글