

👇코드 예제
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Awake()
{
int a = 5 + 6;
int b = a - 3;
int c = a * b;
int d = c / 8;
int e = d % 4;
Debug.Log(a + " = 5 + 6");
Debug.Log($"{a} = 5 + 6");
Debug.Log($"{b} = {a} - 3");
Debug.Log($"{c} = {a} * {b}");
Debug.Log($"{d} = {c} / 6");
Debug.Log($"{e} = {d} % 4");
}
}
👇실행결과

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Awake()
{
int a = 10;
Debug.Log($"a = 10 : {a}");
a += 10;
Debug.Log($"a += 10 : 결과 값 {a}");
// 문자열 보간의 보간식에 수식을 넣어서 연산
Debug.Log($"a -= 9 : 결과 값 {a -= 9}");
Debug.Log($"a *= 8 : 결과 값 {a *= 8}");
Debug.Log($"a /= 7 : 결과 값 {a /= 7}");
Debug.Log($"a %= 6 : 결과 값 {a %= 6}");
Debug.Log($"a &= 5 : 결과 값 {a &= 5}");
Debug.Log($"a |= 4 : 결과 값 {a |= 4}");
Debug.Log($"a ^= 3 : 결과 값 {a ^= 3}");
Debug.Log($"a <<= 2 : 결과 값 {a <<= 2}");
Debug.Log($"a >>= 1 : 결과 값 {a >>= 1}");
}
}
👇실행결과


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Awake()
{
int a = 10;
Debug.Log(a);
a++; // 후위 증가 연산자
Debug.Log(a);
++a; // 전위 증가 연산자
Debug.Log(a);
Debug.Log(a++); // Debug.Log() 실행 후 a 값 증가
Debug.Log(a);
Debug.Log(++a); // a 값 증가 후 Debug.Log() 실행
Debug.Log(a);
}
}
👇실행결과

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Awake()
{
int x = 5, y = 2;
Debug.Log($"{x} > {y} = {x > y}");
Debug.Log($"{x} < {y} = {x < y}");
Debug.Log($"{x} >= {y} = {x >= y}");
Debug.Log($"{x} <= {y} = {x <= y}");
Debug.Log($"{x} == {y} = {x == y}");
Debug.Log($"{x} != {y} = {x != y}");
}
}
👇실행결과