반응형
지금까지 수 없는 반복작으로 실패를 거듭해 조금이라도 기억을 하기 위해서
블로그에 기록으로 남기기로 시작했습니다.
언제 모든 작업 순서가 머리속에 들어와 줄지는 자신이 없지만 그래서 최선을 다하고 있습니다.
최대한 빨리 한가지 게임을 출시를 해서 수익화로 만들어 내고 싶습니다.
그래서 두 번째 게임, 세번째 게임까지는 만들어 나갈 생각입니다.
누구나 좋아할 수 있는 워드게임[Words Game] 으로 만들어 나갈 생각입니다.
예를 들어 3살 아이부터 80세 큰형님까지 평생 기억에 남을만한 게임으로 만들어 낼 생각입니다.
InputManager.cs
public void CheckWord()
{
string wordToCheck = wordContainers[currentWordContainerIndex].GetWord();
string secretWord = WordManager.instance.GetSecretWord();
wordContainers[currentWordContainerIndex].Colorize(secretWord);
keyboardColorizer.Colorize(secretWord, wordToCheck);
if (wordToCheck == secretWord)
Debug.Log("Level Complete");
else
{
Debug.Log("Wrong word");
canAddLetter = true;
DisableTryButton();
currentWordContainerIndex++;
}
}
public class InputManager : MonoBehaviour
{
[Header("Elements")]
[SerializeField] private WordContainer[] wordContainers;
[SerializeField] private Button tryButton;
[SerializeField] private KeyboardColorizer keyboardColorizer;
[Header("Settings")]
private int currentWordContainerIndex;
private bool canAddLetter = true;
여기까지 설정을 하고
KeyboardColorizer.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeyboardColorizer : MonoBehaviour
{
[Header("Elements")]
private KeyboardKey[] Keys;
private void Awake()
{
// Find all KeyboardKey components in the scene
Keys = GetComponentsInChildren<KeyboardKey>();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Colorize(string secretWord, string wordToCheck)
{
for (int i = 0; i < Keys.Length; i++)
{
char keyletter = Keys[i].GetLetter();
for (int j = 0; j < secretWord.Length; j++)
{
if (keyLetter ! == wordToCheck[j])
continue;
// Check if the letter is in the correct position
if(keyLetter == secretWord[j])
{
//Valid
Keys[i].SetValid();
}
else if (secretWord.Contains(keyLetter))
{
//Potential
Keys[i].SetPotential();
}
else
{
//Invalid
Keys[i].SetSetInvalid();
}
}
}
}
}
그리고 나서
KeyboardKey.cs
public class KeyboardKey : MonoBehaviour
{
[Header(" Elements ")]
[SerializeField] private new Image renderer;----------->추가
[SerializeField] private TextMeshProUGUI letterText;
[Header(" Evevts ")]
public static Action<char> OnKeyPressed;
// Start is called before the first frame update
void Start()
{
GetComponent<Button>().onClick.AddListener(SendKeyPressedEvent);
}
private void SendKeyPressedEvent()
{
OnKeyPressed?.Invoke(letterText.text[0]);
}
------------------------------------------------------------------------------
전체 추가
public char GetLetter()
{
return letterText.text[0];
}
public void SetValid()
{
renderer.color = Color.green;
}
public void SetPotential()
{
renderer.color = Color.yellow;
}
public void SetInvalid()
{
renderer.color = Color.gray;
}
}
반응형
'IT > programming' 카테고리의 다른 글
UIM, Data Next 작업 진행순서 (0) | 2025.06.21 |
---|---|
UIManager.cs , DataManager.cs 코드 작성 및 실행결과 (0) | 2025.06.20 |
Background, Submit Button, KeyboardKey 9-Slice , Shadow (0) | 2025.06.19 |
Main Canvas에 Submit Button, Backspae Key 코드 추가작업 (0) | 2025.06.18 |
WordContainer, InputManager, WordManager 까지 코드정리 (0) | 2025.06.18 |