본문 바로가기
반응형

전체 글382

유니티 C# 예외처리 Try Catch Finally 문 간단 사용법 Try Catch Finally 문을 사용하는 이유는? 프로그램 실행 중 예외상황이 발생하면 프로그램이 멈춰버리기 때문에 예외처리를 해줘서 멈추지 않게 만들어줍니다. 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class Example : MonoBehaviour { int a = 0; int b = 0; int result = 0; private void Start() { try { result = a + b; Debug.Log(result); } catch (NullReferenceException e) { Debug.Log("오류 내용 : " + e); }.. 2022. 6. 30.
유니티 C# 반복문 for, foreach, While 문 간단 사용법 For문 for (int i = 0; i < 10; i++) { Debug.Log("Iteration " + i); } Foreach문 int[] numbers = {1, 2, 3, 4, 5}; foreach (int number in numbers) { Debug.Log("Number: " + number); } While문 int count = 0; while (count < 5) { Debug.Log("Count: " + count); count++; } 2022. 6. 30.
유니티 C# 조건문 if, else, Swtich 문 간단 사용법 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { int a = 0; int b = 0; string s = "안녕하세요"; string t = "반갑습니다"; private void Start() { if (a > b) { Debug.Log("a가 b보다 큽니다."); } else { Debug.Log("a가 b보다 같거나 작습니다."); } if (s.Equals(t)) { Debug.Log("서로 같습니다."); } else { Debug.Log("서로 다릅니다."); } switch(a) { case.. 2022. 6. 30.
유니티 플레이팹 구글 로그인 Playfab Sign In with Google Login 간단 구현 구글 로그인 SDK 설치 GitHub - playgameservices/play-games-plugin-for-unity: Google Play Games plugin for Unity Google Play Games plugin for Unity. Contribute to playgameservices/play-games-plugin-for-unity development by creating an account on GitHub. github.com 구글 로그인 구현 using GooglePlayGames; using GooglePlayGames.BasicApi; using PlayFab; using PlayFab.ClientModels; using PlayFab.Json; using PlayFab... 2022. 6. 22.
유니티 플레이팹 게스트 로그인 Playfab Sign In with Guest Login 간단 사용법 코드 작성 using PlayFab; using PlayFab.ClientModels; using PlayFab.Json; using PlayFab.ProfilesModels; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using EntityKey = PlayFab.ProfilesModels.EntityKey; public class PlayfabManager : MonoBehaviour { static string customId = ""; static string playfabId = ""; private string entityId; priva.. 2022. 6. 21.
유니티 C# Application 관련 API 사용법 모음 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public Text versionText; private void Awake() { Application.targetFrameRate = 60; //프레임 조절 Screen.sleepTimeout = SleepTimeout.NeverSleep; //잠들지 않도록 설정 Screen.sleepTimeout = SleepTimeout.SystemSetting; //시스템 설정 사용 versionText.text = Application.version;.. 2022. 6. 21.
유니티 C# 이벤트 델리게이트 delegate Event 간단 사용법 델리게이트 선언 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public delegate void GameEvent(); //이벤트 선언 public static event GameEvent eGameStart, eGamePause, eGameEnd; public delegate void ScoreEvent(int number); //이벤트 선언 public static event ScoreEvent ePlusScore, eMinusScore; private void Start() { eGameStar.. 2022. 6. 21.
유니티 C# 로컬 데이터 저장, 불러오기 PlayerPrefs 간단 사용법 데이터 저장 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Example : MonoBehaviour { private void SetValue() { PlayerPrefs.SetFloat("Apple", 1.0f); PlayerPrefs.SetInt("Orange", 1); PlayerPrefs.SetString("Banana", "Banana"); } } 데이터 불러오기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Example : MonoBehaviour { pri.. 2022. 6. 21.
유니티 C# 타이머 만들기 시분초 00:00:00 Timer 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public Text timerText; public int timer = 0; private void Start() { StartCoroutine(TimerCoroution()); } IEnumerator TimerCoroution() { timer += 1; timerText.text = (timer / 3600).ToString("D2") + ":" + (timer / 60 % 60).ToString("D2") + ":" + (timer % .. 2022. 6. 21.
유니티 C# 충돌 처리 OnTrigger Enter, Stay, Exit 간단 사용법 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "Player") { Debug.Log("플레이어와 접촉 시작"); } } public void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Player") { Debug.Log("3D 플레이어와 접촉중"); } } public void OnTriggerExit(Col.. 2022. 6. 21.
유니티 C# 코루틴 동작, 시간 딜레이 Coroutine, Invoke 간단 사용법 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class Example : MonoBehaviour { private void Start() { StartCoroutine(DelayCoroution()); Invoke("Delay", 5); } IEnumerator DelayCoroution() { yield return new WaitForSeconds(5); Debug.Log("5초가 지났습니다."); } void Delay() { Debug.Log("5초가 지났습니다."); } } .. 2022. 6. 21.
유니티 C# 씬 로드 동기, 비동기 간단 사용법 Load Scene Async 씬 동기 로드 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class Example : MonoBehaviour { public void LoadScene(int number) { SceneManager.LoadScene(number); } public void LoadScene(string name) { SceneManager.LoadScene(name); } } 씬 비동기 로드 using System.Collections; using System.Collections.Generic; using.. 2022. 6. 21.
반응형