반응형
InputManager.cs
private void SetLevelComplete()
{
UpdateData();----------추가 작업
GameManager.instance.SetGameState(GameState. LevelComplete);
}
private void SetLevelComplete()
{
UpdateData();
GameManager.instance.SetGameState(GameState. LevelComplete);
}
private void UpdateData()-------->아래로 3줄 신규추가
{
int scoreToAdd = 6 - currentWordContainerIndex;
DataManager.instance.IncreaseScore(scoreToAdd);
DataManager.instance.AddCoins(scoreToAdd * 3);
}
UIManager.cs
[Header(" Level Complete Elements ")]
[SerializeField] private TextMeshProUGUI levelCompleteCoins;
[SerializeField] private TextMeshProUGUI levelCompleteSecretWord;
[SerializeField] private TextMeshProUGUI levelCompleteScore;
[SerializeField] private TextMeshProUGUI levelCompleteBestScore;
[Header(" Game Elements ")]--------->아래로 2줄 추가
[SerializeField] private TextMeshProUGUI gameScore;
[SerializeField] private TextMeshProUGUI gameCoins;
void Update()
{
}
private void ShowGame()---------->아래 2줄 추가
{
gameCoins.text = DataManager.instance.GetCoins().ToString();
gameScore.text = DataManager.instance.GetScore().ToString();
ShowCG(gameCG);
}
그리고 다시 GameManager.cs 코드 추가작업을 한다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public enum GameState { Menu, Game, LevelComplete, Gameover, Idle}
public class GameManager : MonoBehaviour
{
public static GameManager instance;
[Header(" Settings ")]
private GameState gameState;
[Header(" Events ")]
public static Action<GameState> onGameStateChanged;
private void Awake()
{
if (instance == null)
instance = this;
else
Destroy(gameObject);
}
public void SetGameState(GameState gameState)
{
this.gameState = gameState;
onGameStateChanged?.Invoke(gameState);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void NextButtonCallback()--------->아래 1줄 추가작업
{
SetGameState(GameState.Game);
}
}
UIManager.cs
private void GameStateChangedCallback(GameState gameState)
{
switch (gameState)
{
case GameState.Game:---------->아래 3줄 추가작업
ShowGame();
HideLevelComplete();
break;
case GameState.LevelComplete:
ShowLevelComplete();
HideGame();
break;
}
}
Hierarchy 화면설정
그대로 계속 작업이 이어 집니다.
InputManager.cs
{
Initialize();
KeyboardKey.OnKeyPressed += KeyPressedCallback;
GameManager.onGameStateChanged += GameStateChangedCallback;-------> 추가작업
}
private void OnDestroy()
{
KeyboardKey.OnKeyPressed -= KeyPressedCallback;
GameManager.onGameStateChanged -= GameStateChangedCallback;-------->추가작업
}
private void GameStateChangedCallback(GameState gameState)----------->아래로 모두 추가작업
{
switch (gameState)
{
case GameState.Game:
Initialize();
break;
case GameState.LevelComplete:
break;
}
}
void Update()
{
}
private void Initialize()
{
currentWordContainerIndex = 0;------>추가 작업
canAddLetter = true;------>추가 작업
DisableTryButton();------>추가 작업
for (int i = 0; i < wordContainers.Length; i++)
wordContainers[i].Initialize();
}
계속이어집니다.
WordContainer.cs
void Update()
{
}
public void Initialize()
{
currentLetterIndex = 0;---------->추가작업
for (int i = 0; i < letterContainers.Length; i++)
letterContainers[i].Initialize();
}
계속 이어집니다.
KeyboardColorizer.cs
public class KeyboardColorizer : MonoBehaviour
{
[Header(" Elements ")]
private KeyboardKey[] keys;
public KeyboardColorizer()-------------> 추가작업
{
}
private void Awake()
{
// Find all KeyboardKey components in the scene
keys = GetComponentsInChildren<KeyboardKey>();
}
void Start()-----------> 아래로 모두 추가작업
{
GameManager.onGameStateChanged += GameStateChangedCallback;
}
private void OnDestroy()
{
GameManager.onGameStateChanged -= GameStateChangedCallback;
}
private void GameStateChangedCallback(GameState gameState)
{
switch (gameState)
{
case GameState.Game:
Initialize();
break;
case GameState.LevelComplete:
break;
}
}
private void Initialize()
{
for (int i = 0; i < keys.Length; i++)
{
// Removed the call to Initialize() as it does not exist in KeyboardKey
// If additional setup is needed for KeyboardKey, it should be implemented here
}
}
실행 최종결과
반응형
'새내기 게임 개발자[Unity]' 카테고리의 다른 글
UIManager.cs , DataManager.cs 코드 작성 및 실행결과 (0) | 2025.06.20 |
---|---|
Keyboard Colorize 코드작업 (0) | 2025.06.19 |
Main Canvas에 Submit Button, Backspae Key 코드 추가작업 (0) | 2025.06.18 |
WordContainer, InputManager, WordManager 까지 코드정리 (0) | 2025.06.18 |
Words Game 오픈이 드디어 얼마 남지가 않았다. (0) | 2025.06.05 |