---
title: "클래스"
content_type: tutorial
url: "https://learn.unity.com/tutorial/keulraeseu?language=ko"
language: ko
difficulty: beginner
duration_minutes: 10
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko&version=4.x"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/classes-5.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/clases-wm.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/classes-5-jp.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/keulraeseu.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/lei-l92v5.md?language=zh-cn"
last_updated: "2026-08-04T14:24:42.000Z"
---

# 클래스

C# 클래스에 데이터를 구조화하고, 클래스의 일부를 초기화하는 생성자를 작성하는 방법을 배웁니다.

클래스를 사용하여 정보를 저장하고 구성하는 방법과, 클래스의 일부와 함께 작동하는 생성자를 생성하는 방법을 알아봅니다.

이 튜토리얼은 [스크립팅의 기초 프로젝트](https://learn.unity.com/project/beginner-gameplay-scripting)에 포함되어 있습니다.

이전: [데이터 유형](https://learn.unity.com/tutorial/data-types?projectId=5c8920b4edbc2a113b6bc26a)

다음: [인스턴스화](https://learn.unity.com/tutorial/instantiate?projectId=5c8920b4edbc2a113b6bc26a)

## 1. 클래스

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/4c7da419-102d-4589-99a1-0622f016eb29_U_Beginner_21_Classes.mp4) ([Transcript (ko_kr)](https://connect-mediagw.unity.com/h1/20220427/26ba0d57-93ad-43b4-b56d-202a1cddad28_21_Classes.ko.vtt))

## **SingleCharacterScript**

```csharp
using UnityEngine;
using System.Collections;

public class SingleCharacterScript : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
    }
    
    
    public Stuff myStuff = new Stuff(10, 7, 25);
    public float speed;
    public float turnSpeed;
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;
    
    
    void Update ()
    {
        Movement();
        Shoot();
    }
    
    
    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
    
    
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            myStuff.bullets--;
        }
    }
}
```

## **Inventory**

```csharp
using UnityEngine;
using System.Collections;

public class Inventory : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        public float fuel;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
        
        public Stuff(int bul, float fu)
        {
            bullets = bul;
            fuel = fu;
        }
        
        // 생성자
        public Stuff ()
        {
            bullets = 1;
            grenades = 1;
            rockets = 1;
        }
    }
    

    // Stuff 클래스의 인스턴스(오브젝트) 생성
    public Stuff myStuff = new Stuff(50, 5, 5);
    
    public Stuff myOtherStuff = new Stuff(50, 1.5f);
    
    void Start()
    {
        Debug.Log(myStuff.bullets); 
    }
}
```

## **MovementControls**

```csharp
using UnityEngine;
using System.Collections;

public class MovementControls : MonoBehaviour
{
    public float speed;
    public float turnSpeed;
    
    
    void Update ()
    {
        Movement();
    }
    
    
    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
}
```

## **Shooting**

```csharp
using UnityEngine;
using System.Collections;

public class Shooting : MonoBehaviour
{
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;
    
    
    private Inventory inventory;
    
    
    void Awake ()
    {
        inventory = GetComponent<Inventory>();
    }
    
    
    void Update ()
    {
        Shoot();
    }
    
    
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && inventory.myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            inventory.myStuff.bullets--;
        }
    }
}
```
