250417 TIL

박소희·2025년 4월 17일

Unity_7기

목록 보기
71/94

레이케스트가 어떠한 컴포넌트를 감지하려면 콜라이더가 있어야 한다.

if (Physics.Raycast(ray, out hit, maxCheckDistance, layerMask))
{
    if (hit.collider.gameObject != curInteractGameObject)
    {
        curInteractGameObject = hit.collider.gameObject;
        curInteractable = hit.collider.GetComponent<IInteractable>();
        SetText();
    }
}

자식 객체에 콜라이더가 있어서 감지를 못했다. -> 유지하려면 GetComponentInChildren

배열 내 빈자리 없이 정렬

    public void MoveBlockAndShift(int fromIndex, int toIndex)
    {
        if (fromIndex < 0 || fromIndex >= PlacedBlocks.Count) return;

        if (toIndex < 0) toIndex = 0;
        if (toIndex >= PlacedBlocks.Count) toIndex = PlacedBlocks.Count - 1;

        Block blockToMove = PlacedBlocks[fromIndex];
        PlacedBlocks.RemoveAt(fromIndex);

        PlacedBlocks.Insert(toIndex, blockToMove );
    }

0개의 댓글