개발/유니티(UNITY)

2.4.2 변수와 연산

새벽감성개발자 2023. 9. 7. 09:00
반응형

2.4.2 변수와 연산

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int answer;
        answer = 1 + 2;
        Debug.Log(answer);
    }
}

결과값 보기

※ 사칙 연산하기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int answer;
        answer = 3 - 4;
        Debug.Log(answer);

        answer = 5 * 6;
        Debug.Log(answer);

        answer = 8 / 4;
        Debug.Log(answer);
    }
}

결과값 보기

더보기
-1
30
2

※ 변수와 변수 연산하기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int n1 = 8;
        int n2 = 9;
        int answer;
        answer = n1 + n2;
        Debug.Log(answer);
    }
}

결과값 보기

※ 변수 값 증가시키기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int answer = 10;
        answer += 5;
        Debug.Log(answer);
    }
}

결과값 보기

 

※ 값을 1만큼 증가시키기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int answer = 10;
        answer++;
        Debug.Log(answer);
    }
}

결과값 보기

 

문자열과 문자열의 연결

※ 문자열과 문자열 연결하기1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string str1 = "happy ";
        string str2 = "birthday";
        string message;

        message = str1 + str2;
        Debug.Log(message);
    }
}

결과값 보기

더보기

happy birthday

 

※ 문자열과 문자열 연결하기2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string str1 = "happy ";
        string str2 = "birthday";

        str1 += str2;
        Debug.Log(str1);
    }
}

결과값 보기

더보기

happy birthday

 

※ 문자열과 숫자 연결하기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;                  // 유니티가 동작하는데 필요한 기능 제공


public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string str = "happy ";
        int num = 123;

        string message = str + num;
        Debug.Log(message);
    }
}

결과값 보기

더보기

happy 123

 

반응형

'개발 > 유니티(UNITY)' 카테고리의 다른 글

2.5.5 for 문으로 반복하기  (0) 2023.09.07
2.5 제어문 사용하기  (0) 2023.09.07
2.3 스크립트 첫 걸음  (0) 2023.09.06
2 C# 스크립트 기초  (0) 2023.09.06
1.5.7 기타 기능  (0) 2023.09.05