[Unity] Zerry Library (2) : Light Flicker Animation with Sound Effect

suhan0304·2024년 7월 5일

유니티 - Zerry Library

목록 보기
2/11
post-thumbnail

Assets

  • DOTween
  • UniTask
  • Odin Inspector

Sample


Hierachy


Textures

Circulo.png


Scipts

using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Random = UnityEngine.Random;
using Sirenix.OdinInspector;

public class LightFlickerAnimation : MonoBehaviour
{
    [SerializeField] private Image image;
    [SerializeField] private AudioSource flickerSound;
    
    [Button("Light Off Flicker")]
    // Light off flicker
    void LightOff() {
        image.DOFade(0.3f, Random.Range(0.4f, 0.45f))
            .From(1)
            .SetEase(Ease.OutFlash, 6)
            .OnStart(() => flickerSound.Play())
            .OnComplete(() =>  image.DOFade(0, 0));
    }

    [Button("Light On Flicker")]
    // Light on flicker
    void LightOn() {
        image.DOFade(1f, Random.Range(0.2f, 0.4255f))
            .From(0)
            .SetEase(Ease.InFlash, 5)
            .OnStart(() => flickerSound.Play());
    }
}

profile
Be Honest, Be Harder, Be Stronger

0개의 댓글