[4Idle - GroundZero] Player 사망 연출 게임씬에 적용
-빈 오브젝트를 생성해 PlayerDie 스크립트를 넣어준다.
-이 오브젝트를 GameMain에 할당한다.
-gameMain의 update에서 플레이어의 hp가 0이하가 될때 PlayerDie 스크립트의 PlayerDeath 메서드를 호출한다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerDie : MonoBehaviour
{
[SerializeField] GameObject teleportGo;
[SerializeField] Canvas teleportCanvas;
[SerializeField] Canvas dieCanvas;
public void PlayerDeath()
{
Debug.Log("Player Die!");
StartCoroutine(this.CoChangeColor());
}
private IEnumerator CoChangeColor()
{
this.teleportGo.SetActive(true);
var images = this.teleportCanvas.GetComponentsInChildren<Image>();
int countTime = 0;
while (countTime < 20)
{
if (countTime % 2 == 0)
{
for (int i = 0; i < images.Length; i++)
{
images[i].color = new Color32(77, 26, 26, 255);//to red
}
this.dieCanvas.gameObject.SetActive(true);
}
else
{
for (int i = 0; i < images.Length; i++)
{
images[i].color = new Color32(67, 67, 67, 255);//to black
this.dieCanvas.gameObject.SetActive(false);
}
}
yield return new WaitForSeconds(0.25f);
countTime++;
}
yield return new WaitForSeconds(0.1f);
Debug.Log("fade Out");
this.dieCanvas.gameObject.SetActive(true);
var image = this.dieCanvas.GetComponentInChildren<Image>();
image.color = new Color32(0, 0, 0, 0);
var color = image.color;
while (true)
{//fade out
Debug.Log(color.a);
color.a += 0.01f;
image.color = color;
if (color.a >= 1)
{
SceneManager.LoadScene("GameOverScene");
break;
}
yield return null;
}
}
}
'[VR] GroundZero 개발' 카테고리의 다른 글
[4Idle - GroundZero] damage text의 애니메이션 효과 및 연출 추가 (0) | 2024.01.12 |
---|---|
[4Idle - GroundZero] startScene - LobbyScene 연결 및 startScene 수정 (0) | 2024.01.11 |
[4Idle - GroundZero] Enemy Animation & attack 오브젝트 수정 (0) | 2024.01.08 |
[4Idle - GroundZero] Zepplin 게임 씬에 추가 (1) | 2024.01.05 |
[4Idle - GroundZero] Wave 기능 구현 2 (0) | 2024.01.04 |