목록Development/Unity (3)
Tegi Log : 블록체인, 축구, 소레어, Sorare 컨텐츠망상공간

💡 PlayerPrefs를 이용해서 데이터를 저장하고 불러와보자. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //PlayerPrefs. // [쓰기(세팅)] //SetString(); 키를 지정해서 string 타입의 값을 저장 //SetInt(); 키를 지정해서 int 타입의 값을 저장 //SetFloat(); 키를 지정해서 float 타입의 값을 저장 // [검사] //HasKey(); 해당 키가 존재하는지 검사 bool타입으로 반환해줌. // [읽기(로딩)] //GetString(); 지정한 키의 String 타입 값을 읽어옴. //GetInt(); 지정한 키의 ..
💡 상태를 관리할때 자주 쓰이는 열거형 변수 enum에 대해서 알아봅시다. public class EnumSwitch : MonoBehaviour {//열거형 변수 CatState 상태정의 public enum CatState{ IDLE, MEAW, RUN }; // catState 변수선언 public CatState catState; void Update() { // switch()인자로 catState 변수전달 switch (catState) { // case 띄고 CatState.상태:(변수명이 아니라 타입명을 쳐야됨){ 실행문 } case CatState.IDLE:{ Debug.Log("IDLE!"); } break; //break; 조건에 만족하는 실행문이 끝나면 break에서 멈춘다. cas..
💡 싱글톤 패턴은 클래스객체를 하나로 제한해서 쓰고 싶을때 쓰는 디자인패턴입니다. 게임매니저 같은 전체적인 데이터를 관리할때 쓰곤 합니다. public class GameManager : MonoBehaviour { //게임매니저 변수 선언. public static GameManager instance; private void Awake() { //GameManager 변수 instance가 없다면 this(게임매니저클래스)를 instance에 대입. if(instance == null){ instance = this; //게임매니저 클래스가 아니라면 게임오브젝트를 제거한다. }else if(instance != this){ Destroy(gameObject); } //씬이 전환되도 게임오브젝트가 유지..