핵심 기능구현은 전부 끝내놓은 시점에서 사실상 지금은 계속해서 보완하고 자잘한 기능들을 추가하는 단계이다
이번글에서는 일시정지 버튼을 눌렀을때 실제로 게임을 일시정지 시키고, 맨 처음 나오는 인트로씬을 보완해보겠다
(17) 개인 프로젝트 - inGame Scene #Pause
모든 씬들이 전부 연결된줄 알았지만 한가지 놓친게 있었다. 바로 인게임씬과 다른 씬들과의 연결이었다. 아이템에 본격적으로 넘어가기전에, 다른 모든걸 전부 구현을 시키고 넘어가고 싶기에
sangeun00.tistory.com
위 글의 보완내용이다
<일시정지 구현>
인게임화면 우측 가운데 보이는 일시정지 버튼을 누르면 일시정시 창이 활성화되지만
정작 화면뒤에 보이는 오브젝트들은 정지되지 않고 계속해서 진행중이다
우선 일시정지 버튼을 누르면 게임이 정지되고, x버튼과 Resume 버튼을 누르면 창이 닫히면서 재개
Restart버튼과 Main menu버튼은 게임을 재개하면서 각자의 기능을 수행하도록 만들겠다
여기서 쓰일 핵심기능은 바로 Time.timeScale 이라는 기능이다. 쉽게 말해
Time.timeScale = 0 (정지)
Time.timeScale = 1 (재생)
Time.timeScale = 2 (2배속)
이렇게 생각하면 된다. 정말 간단하다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainButtonManager : MonoBehaviour
{
public Button Stopbtn;
public Button Xbtn;
public Button Resume;
public Button Restart;
public Button Main_menu;
public GameObject Stop_Channel;
public AudioSource ButtonAudio;
bool ispause;
void Start()
{
ispause = false;
this.Stopbtn.onClick.AddListener(() =>
{
ButtonAudio.Play();
this.Stop_Channel.gameObject.SetActive(true);
Time.timeScale = 0;
ispause = true;
});
this.Xbtn.onClick.AddListener(() =>
{
ButtonAudio.Play();
this.Stop_Channel.gameObject.SetActive(false);
Time.timeScale = 1;
ispause = false;
return;
});
this.Resume.onClick.AddListener(() =>
{
ButtonAudio.Play();
this.Stop_Channel.gameObject.SetActive(false);
Time.timeScale = 1;
ispause = false;
return;
});
this.Restart.onClick.AddListener(() =>
{
ButtonAudio.Play();
this.Stop_Channel.gameObject.SetActive(false);
Time.timeScale = 1;
ispause = false;
SceneManager.LoadScene("Main Scene");
});
this.Main_menu.onClick.AddListener(() =>
{
ButtonAudio.Play();
this.Stop_Channel.gameObject.SetActive(false);
Time.timeScale = 1;
ispause = false;
SceneManager.LoadScene("Start Scene");
});
}
}
위처럼 코드를 짜주고 각각 알맞는 버튼을 집어넣어주면 된다
일시정지와 재생 기능이 정상적으로 동작하는것을 볼 수 있다
<인트로씬 보완>
(22) 개인 프로젝트 - 인트로씬 & Json 응용 연습
이번엔 임시로 쓰일 인트로씬을 만들고 Json으로 스테이지를 만드는 연습을 해보겠다 게임을 실행하면 나오는 회사만의 로고들을 나도 만들어보겠다 그림판으로 그린 귀여운 로고. 핸드폰 비
sangeun00.tistory.com
사실 보완이래봐야 별건 없지만 게임 실행시 맨처음 나타나는
요 사진 다음에 올 사진을 2장 정도 추가하여 순서대로 페이드인/아웃 할 예정이다
직접 그린 2장이 순서대로 나오도록 하며,
현재 활성화중인 그림 외 나머지 2장은 자동으로 비활성화 되도록 하겠다
그리고 마지막 3번째 그림까지 페이드아웃 된다면 Start Scene으로 넘어가도록 하겠다
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class FadeInOut : MonoBehaviour
{
public Image[] images;
public float fadeTime = 2f;
void Start()
{
StartCoroutine(SequentialFadeEffect());
}
IEnumerator SequentialFadeEffect()
{
for (int i = 0; i < images.Length; i++)
{
yield return StartCoroutine(FadeEffect(images[i]));
// 현재 이미지 비활성화
images[i].gameObject.SetActive(false);
}
SceneManager.LoadScene("Start Scene");
}
IEnumerator FadeEffect(Image image)
{
image.gameObject.SetActive(true); // 이미지 활성화
for (float t = 0f; t <= 1f; t += Time.deltaTime / fadeTime)
{
Color newColor = image.color;
newColor.a = Mathf.Lerp(0f, 1f, t);
image.color = newColor;
yield return null;
}
yield return new WaitForSeconds(1.5f); // 최고점에서 대기
for (float t = 0f; t <= 1f; t += Time.deltaTime / fadeTime)
{
Color newColor = image.color;
newColor.a = Mathf.Lerp(1f, 0f, t);
image.color = newColor;
yield return null;
}
}
}
이미지가 2장을 넘어가니 배열로 바꾸어 여러장 받을수 있도록 하였고 for문으로 마지막장까지 반복하여
페이드인/아웃을 구현하였다
3장이 차례대로 페이드인/아웃이 되는것을 확인할 수 있다
'Galaxy Ball > 1. 멀티플레이 - 대전모드' 카테고리의 다른 글
(25) UI - Item Slot & UI Camera (0) | 2024.05.02 |
---|---|
(24) 아이템으로 패배판정 & 아이템 획득 & 충돌판정 (1) | 2024.05.02 |
(22) 인트로씬 & Json 응용 연습 (0) | 2024.04.30 |
(21) 아이템 #아이템 밸런스 조절 & 기능구현 (0) | 2024.04.11 |
(20) 아이템 #사용구현 (0) | 2024.04.08 |