FloorPrototype080108 : 수치가 m단위인 큐브
FloorPrototype040104 : scale값을 4로 바꿔주면 -> 4*4=16m 가 되는 것임
shift : 버튼 누르고 움직이면 걸음
c : 앉음
오브젝트 첫 글자는 항상 대문자로
카메라가 따라 다니는게 느린데 이 값을 빠르게 조절 가능함 -> 자습하셈
Intensity : 밝기 조절
Material : 오브젝트와 컴포넌트 사이에 매개체 역할. 텍스쳐를 드랙앤드롭만 해줘도 알아서 생성되는 아주 중요한 존재.
추락하면 아래에 크게 OutArea를 만들어 충돌검사하는 Trigger를 발생시켜 자동 종료되게 한다.
OutArea에 적용시킴
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Out : MonoBehaviour
{
private void OnTriggerEnter(Collider other) //OnTri 까지 치면 자동완성
{
if(other.gameObject.tag == "Player")
{
//플레이어와 충돌되면 현재 씬을 재시작
Application.LoadLevel(Application.loadedLevel); //loadedLevel : 현재 씬을 다시 불러옴.
//SceneManager.LoadScene("Main");와 동일
}
}
}
도착하는 곳에 ResultArea를 만들어 충돌검사하는 Trigger를 발생시켜 자동 종료되게 한다.
충돌 검사만 할거라서 컴포넌트 안 보이게 함. -> Mesh Renderer 체크 해제
GoalArea에 적용시킴
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoalArea : MonoBehaviour
{
public static bool goal; //게임 종료 여부
void Start()
{
goal = false;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
goal = true;
}
}
}
Ugui 방식 : Unity gui 방식이란 뜻
게임이 시작되면 타이머를 시작해 실행 시간을 측정해준다.
TimeText에 적용시킴
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public static float timer;
void Start()
{
timer = 0;
}
void Update()
{
if(GoalArea.goal == false)
{
timer += Time.deltaTime; //시간을 누적
}
int t = Mathf.FloorToInt(timer);
Text uiText = GetComponent<Text>();
uiText.text = "Time : " + t.ToString();
}
}
canvas에 적용시킨 후
ResultTime
과BestTime
변수를 넣어준다.
이 키 값은 레지스트리 편집기에 저장된다.
HKEY_CURRENT_USER -> Software -> Unity -> UnityEditor -> DefaultCompany
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameResult : MonoBehaviour
{
private int highScore; //최고기록 저장
public Text resultTime; //현재기록 텍스트
public Text bestTime; //최고기록 텍스트
public GameObject parts; //UI 오브젝트들 활성 / 비활성화
void Start()
{ //HasKey 에 HighScore값이 있는지 검사 후 불러옴
if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore"); //있다면 값 얻어옴
}
else
{
highScore = 999; //없으면 999로 초기화
}
}
void Update()
{
if (GoalArea.goal) //플레이어가 목표지점에 도착했다면..
{
//엔딩씬 구현하려면 여기서 화면 전환이 이루어져야 함.
parts.SetActive(true); //결과화면 UI들 활성화
int result = Mathf.FloorToInt(Timer.timer); //현재 기록 불러옴
resultTime.text = "ResultTime : " + result; //화면에 현재 기록 표시
bestTime.text = "BestTime : " + highScore; //최고 기록 표시
if (highScore > result) // 새로운 스코어 갱신했다면
{
//새로운 기록 발생 시 HighScore 키값에 result를 저장
PlayerPrefs.SetInt("HighScore", result); //Int/String/Float값을 간편히 저장 가능한 함수
//레지스트리 편집기 Unity -> UnityEditor -> DefaultCompany -> 3DRun에 저장됨
}
}
}
public void OnRetry() //Retry 버튼을 눌렀을 때 실행할 함수
{
SceneManager.LoadScene("Main");
}
}