반응형
코드 작성
유니티의 스프라이트 이미지가 자동으로 커졌다가 작아지는 애니메이션입니다
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;
public class ImageAnimation : MonoBehaviour
{
Image image;
float size = 0;
bool check = false;
WaitForSeconds WaitForSeconds = new WaitForSeconds(0.01f);
private void Awake()
{
image = GetComponent<Image>();
}
[Button]
public void SizeUp()
{
size = 0;
check = false;
transform.localScale = Vector3.zero;
StopAllCoroutines();
StartCoroutine(StarUpAnimation());
}
[Button]
public void SizeDown()
{
size = 1;
check = false;
transform.localScale = Vector3.one;
StopAllCoroutines();
StartCoroutine(StarDownAnimation());
}
IEnumerator SizeUpAnimation()
{
if(!check)
{
if (size < 1.2f)
{
size += 0.04f;
}
else
{
check = true;
}
}
else
{
if(size > 1f)
{
size -= 0.04f;
}
else
{
SoundManager.instance.PlaySFX(GameSfxType.GetStar);
transform.localScale = Vector3.one;
yield break;
}
}
transform.localScale = new Vector3(size, size, size);
yield return WaitForSeconds;
StartCoroutine(StarUpAnimation());
}
IEnumerator SizeDownAnimation()
{
if(size > 0)
{
size -= 0.04f;
}
else
{
SoundManager.instance.PlaySFX(GameSfxType.LoseStar);
transform.localScale = Vector3.zero;
yield break;
}
transform.localScale = new Vector3(size, size, size);
yield return WaitForSeconds;
StartCoroutine(StarDownAnimation());
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 회원가입 간단 구현 PlayerPrefs 활용 (0) | 2023.08.13 |
---|---|
유니티 C# 포물선 궤적 그리기 간단 구현 Parabolic Trajectory (0) | 2023.08.13 |
유니티 C# 스마트폰 위도, 경도, 고도 받아오기 간단 구현 Location (0) | 2023.08.13 |
유니티 C# 길찾기 코드 간단 구현 Path finding (0) | 2023.08.13 |
유니티 C# 이미지 그라데이션 효과 주기 Image Gradient (0) | 2023.08.07 |
유니티 C# 파일 저장 불러오기 간단 구현 File Save Load (0) | 2023.06.07 |
유니티 C# 블록 퍼즐 게임 간단 구현 Block Breaker (0) | 2023.06.07 |
유니티 C# 랭킹 시스템 간단 구현 Unity Rankings (0) | 2023.06.07 |
댓글