Unity
Unity 연산자
olivia-com
2021. 6. 26. 09:02
using UnityEngine;
public class OperatorExample : MonoBehaviour
{
// 1. 산술 연산자
// +,-,*,/,%,++,--
// 2. 대입연산자
// =, 산술연사자와 결합하여 사용
// 3. 논리연산자
// &&(AND), ||(OR), !(NOT)
// 4. 비교연산자
// >,<,<=,>=, ==(같다) => 결과 값이 boolean(true/false)
void Start(){
int a = 10;
int b = 2;
// 산술
Debug.Log(a+b); // 12
Debug.Log(a -b); // 8
Debug.Log(a*b); // 20
Debug.Log(a/b); // 5
Debug.Log(a % b); // 0
Debug.Log(10 % 3); // 1
a++;
b--;
Debug.Log(a); // 11
Debug.Log(b); // 1
// 대입
a = b;
Debug.Log(a); // 1
a += 3; // a = a + 3;
// 논리
bool t = true;
bool f = false;
Debug.Log(t&&f); // false
Debug.Log(t || f); // true
Debug.Log(!t); // false
// 비교
int c = 1;
int d = 3;
Debug.Log(c <= d); // true
Debug.Log(c >= d); // false
Debug.Log(c == d); // false
}
}