오브젝트를 비활성화 해두었다가 Animation의 이벤트를 활용하여 해당 스크립트의 메서드를 불러오는 식으로 구현하였다. 전체적으로 애니메이션의 동작을 코드로 구현하고 싶은데 아직 엔진의 기능을 많이 활용하고 있어서 애니메이션의 타이밍을 맞추는 것이 번거롭고 재사용은 사실상 불가능 할 것 같다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EventReceiver : MonoBehaviour
{
    public int starCount = 3;
    public GameObject[] arrStars;
    public GameObject[] arrParticles;
    public GameObject burst;
    public float watingTime = 0.1f;

    void Start()
    {
        
    }

    public void ApeearBurst()
    {
        this.burst.gameObject.SetActive(true);
    }

    public void ApeearStar()
    {
        StartCoroutine(WaitforTimeStar());
    }

    public void ApeearParticle()
    {
        StartCoroutine(WaitforTimeParticle());
    }

    IEnumerator WaitforTimeStar()
    {
        for (int i = 0; i < this.starCount; i++)
        {
            this.arrStars[i].gameObject.SetActive(true);
            yield return new WaitForSeconds(this.watingTime);
        }
    }

    IEnumerator WaitforTimeParticle()
    {
        for (int i = 0; i < starCount; i++)
        {
            this.arrParticles[i].gameObject.SetActive(true);
            yield return new WaitForSeconds(this.watingTime);
        }
    }
}

 

 

 

 

 

 

'C# > 수업 내용' 카테고리의 다른 글

Unity) [유니티 UI] 정적 스크롤 뷰  (0) 2023.02.13
230208  (0) 2023.02.08
Unity) [유니티 UI] 월드 - 캔버스 좌표 연결  (0) 2023.02.08
230207  (0) 2023.02.07
유니티(Unity) UI - 버튼 구현 유형  (0) 2023.02.06

+ Recent posts