Destroy

Tutorial

Beginner

+10XP

5 mins

(37)

Unity Technologies

Destroy

Destroy() 함수를 사용하여 런타임 시 게임 오브젝트와 컴포넌트를 제거하는 방법을 알아봅니다.

이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.

이전: 선형 보간

다음: GetButton 및 GetKey

1. Destroy

DestroyBasic

using UnityEngine;
using System.Collections;

public class DestroyBasic : MonoBehaviour
{
    void Update ()
    {
        if(Input.GetKey(KeyCode.Space))
        {
            Destroy(gameObject);
        }
    }
}

DestroyOther

using UnityEngine;
using System.Collections;

public class DestroyOther : MonoBehaviour
{
    public GameObject other;
    
    
    void Update ()
    {
        if(Input.GetKey(KeyCode.Space))
        {
            Destroy(other);
        }
    }
}

DestroyComponent

using UnityEngine;
using System.Collections;

public class DestroyComponent : MonoBehaviour
{
    void Update ()
    {
        if(Input.GetKey(KeyCode.Space))
        {
            Destroy(GetComponent<MeshRenderer>());
        }
    }
}

Complete this Tutorial