유니티/기능

유니티 오브젝트에 레이어 이름 추가하기(스크립트로 추가)

MJ_119 2024. 10. 15. 00:37

- 오브젝트에 스크립트를 이용해서 레이어 설정하기

 

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

[RequireComponent(typeof(Rigidbody))]
public class Target : MonoBehaviour
{
    private void Start()
    {
        gameObject.layer = LayerMask.NameToLayer("Enemy");
    }
}