딸기 성장에 방해되는 요소는 모두 구현했고, 이젠 딸기 성장을 돕는 요소인 소나기를 구현할 것이다!
소나기를 내리는 시각적 효과를 구현할 때 유니티에서 제공하는 파티클 시스템을 사용해볼 것이다.
Linear: 파티클의 기울여짐 정도를 나타낸다. X축으로 0.5만큼 기울여 비가 사선으로 내리는 효과를 줬다.
소나기가 올 때 화면을 어둡게 만들어 소나기가 자연스럽게 내리게 보여지도록 도와주는 패널이다. 다른 UI와 겹치지 않도록 Hierarchy 가장 상단에 두어 우선 순위를 낮추었다.
마지막으로 Rain 파티클에 적용돼 있는 RainCtrl 스크립트이다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
public class RainCtrl : MonoBehaviour
{
public GameObject rainPanel;
private ParticleSystem rainParticle;
public float rainPeriod;
public int mult; // 몇 배 가속되는지?
public float rainTime;
private bool isRaining;
void Awake()
{
rainParticle = GetComponent<ParticleSystem>();
}
void Update()
{
if (isRaining) return; // 비가 오고 있다면 리턴
rainTime += Time.deltaTime; // 주기를 위한 타이머
if(rainTime >= rainPeriod) // 타이머가 주기를 넘었다면
{
isRaining = true;
Raining();
StartCoroutine(RainingRoutine());
}
}
void Raining()
{
rainPanel.gameObject.SetActive(true);
rainPanel.GetComponent<Image>().DOFade(0.3f, 0.3f); // Dotween으로 rainPanel 명암 조절
mult = 3;
rainTime = 0;
rainParticle.Play(); // 파티클 실행
}
IEnumerator RainingRoutine()
{
yield return new WaitForSeconds(rainParticle.main.duration);
rainPanel.GetComponent<PanelAnimation>().FadeOut(); // Dotween으로 rainPanel 명암 조절
mult = 1;
isRaining = false;
}
}