유니티로 배우는 c#

구조체

테오구 2021. 10. 10. 10:01
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// struct는 값타입

// class는 주소 타입

public enum Item{
    Weapon,
    Sheild,
    Potion,
}

public struct MyStruct //상속이 불가
{
    public int a; //class와는 다르게 직접적인 값을 대입할 수 없다.

    public MyStruct(int _a, int  _b, int  _c, int  _d){
        //생성자 javaScript의 constructor와 같다
        a = _a; b = _b; c = _c; d = _d;
    }

    public void GetA(int value){
        a = 1;
    }
}

public class test : MonoBehaviour
{
    MyStruct keidy;
    // struct는 선언할 때 MyStruct keidy;를 사용해야하지만\
    // class는 MyStruct keidy = new MyStruct();

    Item item;

    void Start(){
        // keidy.a = 2;

        item = Item.Weapon;

        print(item)
    }
}
728x90

'유니티로 배우는 c#' 카테고리의 다른 글

상속  (0) 2021.10.10
델리게이트  (0) 2021.10.10
네임스페이스  (0) 2021.10.10
컬렉션  (0) 2021.10.03
지정자  (0) 2021.09.30