씬 변경 시, DontDestroyOnLoad(gameObject); 로 이름이 적힌 캔버스를 남김 ㅋ
데이터를 넘겨야 하는데... 일단 했다. GREAT!
할 일:
글자 출력 후, 마우스 버튼을 누르면 씬이 넘어가게
게임 씬이 완료된 후, 이름 입력 씬으로 돌아오게 (이거 했는데 안됨; 왜 안돌아오냐...)
룰렛이 천천히 멈추게.. 타임스케일을 늦추면 될 거 같아..
룰렛이 한 번만 돌게!
한글 폰트가 반은 되고 반은 안됨 ㅋ 이건 몰까.. 되던 글자도 깨질 때가 있다. 임포트를 다시해볼까..
- Roullet
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Roullet : MonoBehaviour
{
float rotSpeed;
float delta = 0;
public bool isStop = false; // 멈추면 트루로 변경해서 니들이 받음
void Update()
{
// 마우스를 클릭하면 지정 속도로 룰렛이 돈다.
if(Input.GetMouseButtonUp(0))
{
this.rotSpeed = Random.Range(5000, 50001); // 사이의 수를 돌리는 속도로 함
Debug.Log(rotSpeed);
delta += Time.deltaTime;
}
// Debug.Log(delta);
transform.Rotate(0, 0, rotSpeed);
// 속도를 줄인다.
this.rotSpeed *= 0.96f;
// Debug.Log(this.rotSpeed);
if (this.rotSpeed < 2 && delta !=0)
{
this.rotSpeed = 0f;
isStop = true;
// Debug.Log($"<color=yellow>멈춤</color>");
}
}
}
- needle
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
public class needle : MonoBehaviour
{
public GameObject Roullet;
float ldelTime = 0;
public GameObject Good;
public GameObject Bad;
public GameObject Great;
public GameObject GBad;
public GameObject So;
public GameObject CARE;
private void Update()
{
if((Roullet.GetComponent<Roullet>().isStop == true))
{
// Debug.Log($"<color=blue>왔어</color>");
ldelTime += Time.deltaTime;
if (ldelTime > 0.2)
{
// Debug.Log("1초");
// 니들 콜라이더 활성화
this.GetComponent<Collider2D>().enabled = true;
}
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.name == "bedcoll")
{
Debug.Log("운수 나쁨");
Bad.SetActive(true);
}
if (collision.name == "Goodcoll")
{
Debug.Log("운수대통");
Great.SetActive(true);
}
if (collision.name == "Bedcolll")
{
Debug.Log("운수 매우 나쁨");
GBad.SetActive(true);
}
if (collision.name == "socoll")
{
Debug.Log("운수 보통");
So.SetActive(true);
}
if (collision.name == "bbedcoll")
{
Debug.Log("운수 조심");
CARE.SetActive(true);
}
if (collision.name == "goodcoll")
{
Debug.Log("운수 좋음");
Great.SetActive(true);
}
this.GameOver();
}
void GameOver()
{
Time.timeScale = 0f; // 작동 멈춤
// Debug.Log("게임오버");
//if (Input.GetMouseButtonDown(1))
//{
//// Debug.Log("탭탭");
// SceneManager.LoadScene("RoulletName");
//}
}
}
- GoRoulletScene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.UI;
public class GoRoulletScene : MonoBehaviour
{
public Button Button;
public TMP_InputField InputText;
public TMP_Text OutputText;
public void Start()
{
this.Button.onClick.AddListener(() =>
{
OutputText.text = InputText.text;
InputText.text = "";
Debug.Log($"출력: {OutputText.text} 입력: {InputText.text}");
});
}
private void Update()
{
if (this.Button != null)
{
this.click(); // 이걸 어케켜?
}
}
void click()
{
if (Input.GetMouseButtonDown(1))
{
Debug.Log("이동");
SceneManager.LoadScene("SampleScene");
DontDestroyOnLoad(gameObject); // 아웃풋 캔버스를 유지함
}
}
}