[24.02.22]Unity - Layer

손지·2024년 2월 22일
0

Unity

목록 보기
13/44

오늘은 Layer


rgb 큐브 세개를 만들고 포지션 초기화합니다.

색깔별로 머테리얼을 만들고 넣어줍니다.

크기도 키워줍니다.

레이어 새로만들어서 R,G,B 를 넣습니다.

그리고 각가2개씩 복사해서 위아래로 배치합니다

그리고 각 큐브들마다 레이어를 넣어줍니다.


스크립트를 만들고,

같은이름의 빈 오브젝트를만들고 스크립트를배치합니다.

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

public class LayerExample : MonoBehaviour
{
    [SerializeField] private LayerMask layerMask;
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if(Physics.Raycast(ray, out hit, Mathf.Infinity, 0))
            {
                Debug.Log(hit.transform.name);
            }
            
        }
    }
}

스크립트에 넣어주면.

이렇게 레이어를 골라줄수있다.

profile
게임 개발자가 될사람

0개의 댓글

관련 채용 정보