Operator 연산자 Operator 연산자 산술 연산자 + - * / (int로 / 사용시 소수점 이하는 버림) 1이 더해지는 결과가 나오는 코드 num = num + 1; num += 1; num++; 1이 빠지는 결과가 나오는 코드 num = num - 1; num -= 1; num--; compare 비교 연산자 >, =, 5; Debug.Log(compare); // True Debug.Log(10 = 5); // True Debug.Log(10 🎮 Unity 개발/C# 2023.08.29
TypeCasting 형변환자 TypeCasting 형변환자 형변환자 - 서로 다른 자료형으로 바꾸는 것 (정수 실수 문자열로 각각) // 정수형 -> 실수형 // int to double double time_d = (double) time; // 실수형 -> 정수형 // double to int time = (int) time_d; // int는 소수점 버려짐 // 정수형, 실수형 -> 문자열 // int, double to string string time_str = time.ToString(); Debug.Log(time_str); // "8" string time_d_str = time_d.ToString(); Debug.Log(time_d_str); // "8.9" // 문자열 -> 정수형, 실수형 // string to .. 🎮 Unity 개발/C# 2023.08.29
주석 주석 주석 = 메모 = 무시 = 테스트할 때 코드를 임시로 막아둘 수도 있다. // 주석 /* 전체 코드 주석 */ 코드 public class _04_Comment : MonoBehaviour { // Start is called before the first frame update void Start() // 주석 = 메모 = 무시 = 테스트할 때 코드 임시로 막아둘 수도 있음 { Debug.Log("Three"); Debug.Log("Two"); Debug.Log("One"); Debug.Log("Start"); // Game Start? or Start? // Debug.Log("Go"); /* 전체 코드 주석 Debug.Log("Ready"); Debug.Log("Go"); */ } // Upd.. 🎮 Unity 개발/C# 2023.08.29
Variable 변수 Variable 변수 변수 - 자료형 값들 저장하기 위한 공간 int 정수 float 실수 숫자끝에 f 붙여야 함, 소수점 몇 자리 안될 때, 선언하고 바로 값 넣기 double 같은 실수인데 광범위, 정밀도 높은 데이터 저장, f 필요 없음 string 문자열 char 문자 (캐릭터) bool Boolean true false 참 거짓에 사용 서로 다른 자료형에 대해서 변수를 만들고 그 변수에 값을 집어넣어서 출력하고 또 변수 값을 업데이트 해서 출력 변수명 규칙 - 언더바 영문자 시작 가능 숫자로 시작 안됨, 숫자가 들어가는건 가능, 띄어쓰기 들어가는거 불가, 영문자로 지으면 됨 코드 public class _03_Variable : MonoBehaviour { // Start is called be.. 🎮 Unity 개발/C# 2023.08.29
DataTypes 자료형 DataTypes 자료형 정수 1, 10, -20 실수 0.1, 3.141592, -10.24 문자열 "Text is Text.", "123" 문자 'A', 'C' Boolean true, false 코드 public class _02_DataTypes : MonoBehaviour { // Start is called before the first frame update void Start() { Debug.Log(1); // 정수 Debug.Log(10); Debug.Log(-20); Debug.Log(0.1); // 실수 Debug.Log(3.141592); Debug.Log(-10.24); Debug.Log("Text is Text."); // 문자열 Debug.Log("123"); Debug.Lo.. 🎮 Unity 개발/C# 2023.08.29
Console Log public class Practice : MonoBehaviour { // Start is called before the first frame update void Start() { Debug.Log("Normal"); Debug.LogWarning("Warning"); Debug.LogError("Error"); for (int i = 0; i < 100; i++){ Debug.Log("Same Log"); // 같은 로그 모아보려면 Console에서 Collapse } } // Update is called once per frame void Update() { } } 🎮 Unity 개발/C# 2023.08.29