jae_coding

[유니티로 배우는 C#] 변수 본문

C#

[유니티로 배우는 C#] 변수

재코딩 2022. 7. 19. 08:54
반응형

Unity C # Script의 기본 구성 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Unity_lecture : MonoBehaviour
{
	// 최초 1회 실행
    void Start()
    {
    }

	// 매 Frame마다 업데이트
    void Update()
    {
        
    }
}

 

변수

예를들어 x의 값에 정수 100을 넣고싶다면

타입 변수명 = 정수 + 세미콜론(;)으로 선언을 해주면된다.

흔히 C언어와 변수를 선언하는 것이 동일하다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


// public class 이름이 script의 이름과 일치시켜야한다.
public class Unity_lecture : MonoBehaviour
{

    // 1 + x = 101
    // 숫자 1: 상수
    // x: 변수 (값을 가르키는 주소)
    
    //x선언
    int x = 100;

    //y선언
    int y = 100;


    // 게임이 시작될 때 최초 1회 시행하는 코드
    void Start()
    {
        // x에 100, y에 100이므로 sum은 200
        sum = x + y;
        // 200을 출력한다.
        print(sum);
        //-200을 출력한다.
        print(-sum);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

강의자료: 케이디 유튜브

반응형
Comments