오늘은 정답보기를 클릭하면 정답 확인되고, 게임 스코어가 증가되도록 합니다.

GameScore 를 만들고 텍스트 게임 오브젝트에 게임 스코어를 할당해봅니다. 텍스트 게임 오브젝트에 점수를 출력합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public Text QuizText;
public Text RightAnswer;
public Text GameScoreText;
public Text ButtonText1;
public Text ButtonText2;
public Text ButtonText3;
List<string> QuizTextArray = new List<string>();
List<string> AnswerTextArray = new List<string>();
public string[] answer;
public int GameScore = 0;
void Awake()
{
instance = this;
}
void Start()
{
QuizTextArray.Add("3+2=");
QuizTextArray.Add("5+4=");
QuizTextArray.Add("7+3=");
AnswerTextArray.Add("5,6,7,5");
AnswerTextArray.Add("8,9,10,9");
AnswerTextArray.Add("9,10,11,10");
string AnswerText = AnswerTextArray[0];
answer = AnswerText.Split(',');
QuizText.text = QuizTextArray[0];
ButtonText1.text = answer[0];
ButtonText2.text = answer[1];
ButtonText3.text = answer[2];
RightAnswer.text = answer[3];
GameScoreText.text = "점수: "+ GameScore;
}
}

GameScore 점수와 선택한 보기와 같으면 게임 점수를 증가합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonCheck : MonoBehaviour
{
public void AnswerButton()
{
Debug.Log("보기: " + this.GetComponentInChildren<Text>().text);
Debug.Log("정답: " + GameObject.FindGameObjectWithTag("RightAnswerText").GetComponent<Text>().text);
Debug.Log("정답: "+ GameManager.instance.answer[3]);
Debug.Log("정답: " + GameManager.instance.GameScore);
if (GameObject.FindGameObjectWithTag("RightAnswerText").GetComponent<Text>().text == this.GetComponentInChildren<Text>().text)
{
Debug.Log("정답입니다~");
GameManager.instance.GameScore += 10;
GameManager.instance.GameScoreText.text = "점수: " + GameManager.instance.GameScore;
}
}
}

다음과 같이 정답 보기를 클릭하면 점수가 10점 증가합니다~~

오늘은 정답보기를 클릭하면 정답 확인되고, 게임 스코어가 증가되도록 합니다.
GameScore 를 만들고 텍스트 게임 오브젝트에 게임 스코어를 할당해봅니다. 텍스트 게임 오브젝트에 점수를 출력합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public Text QuizText;
public Text RightAnswer;
public Text GameScoreText;
public Text ButtonText1;
public Text ButtonText2;
public Text ButtonText3;
List<string> QuizTextArray = new List<string>();
List<string> AnswerTextArray = new List<string>();
public string[] answer;
public int GameScore = 0;
void Awake()
{
instance = this;
}
void Start()
{
QuizTextArray.Add("3+2=");
QuizTextArray.Add("5+4=");
QuizTextArray.Add("7+3=");
AnswerTextArray.Add("5,6,7,5");
AnswerTextArray.Add("8,9,10,9");
AnswerTextArray.Add("9,10,11,10");
string AnswerText = AnswerTextArray[0];
answer = AnswerText.Split(',');
QuizText.text = QuizTextArray[0];
ButtonText1.text = answer[0];
ButtonText2.text = answer[1];
ButtonText3.text = answer[2];
RightAnswer.text = answer[3];
GameScoreText.text = "점수: "+ GameScore;
}
}
GameScore 점수와 선택한 보기와 같으면 게임 점수를 증가합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonCheck : MonoBehaviour
{
public void AnswerButton()
{
Debug.Log("보기: " + this.GetComponentInChildren<Text>().text);
Debug.Log("정답: " + GameObject.FindGameObjectWithTag("RightAnswerText").GetComponent<Text>().text);
Debug.Log("정답: "+ GameManager.instance.answer[3]);
Debug.Log("정답: " + GameManager.instance.GameScore);
if (GameObject.FindGameObjectWithTag("RightAnswerText").GetComponent<Text>().text == this.GetComponentInChildren<Text>().text)
{
Debug.Log("정답입니다~");
GameManager.instance.GameScore += 10;
GameManager.instance.GameScoreText.text = "점수: " + GameManager.instance.GameScore;
}
}
}
다음과 같이 정답 보기를 클릭하면 점수가 10점 증가합니다~~