공부/Unity

[Unity] 도전 2주모작 오버쿡드(4) 자동 정렬 및 주문서

굴러다니다니 2023. 7. 10. 10:31
728x90

1. 폰트 및 약간의 UI 수정

실제랑 매우 흡사하게 제작!

후후

 

2. 책상위에 자동 안착 시스템

각 테이블마다 isTrigger 체크를 켜둔 콜라이더를 넣어줬다

그리고 닿으면 쟤 자식객체로 들어가고 자리 잡게 설정!

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

public class AutoCheck : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        if (!(FindObjectOfType<PlayerController>().transform.childCount > 1 && !FindObjectOfType<PlayerController>().transform.GetChild(1).GetChild(0).GetChild(0).Equals(other)))
        {
            if (other.GetComponent<MeshCollider>() == null)
            {
                return;
            }
            if (!transform.parent.parent.GetChild(0).GetComponent<Object>().onSomething)
            {
                Transform Collider = transform.parent.parent.GetChild(0);
                GameObject handleThing = other.gameObject;
                if (Collider.GetComponent<Object>().type == Object.ObjectType.CounterTop)
                {
                    if (handleThing.CompareTag("Ingredient"))
                    {
                        Collider.GetComponent<Object>().onSomething = true;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().isOnDesk = true;
                        handleThing.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().IngredientAuto(transform.parent.parent, transform.parent.parent.GetChild(1).localPosition, handleThing.transform.GetChild(0).GetComponent<Handle>().hand);
                    }
                    else //접시
                    {
                        Collider.GetComponent<Object>().onSomething = true;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().isOnDesk = true;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().PlayerHandleOff(transform.parent.parent, transform.parent.parent.GetChild(1).localPosition);
                    }
                }
                else if (Collider.GetComponent<Object>().type == Object.ObjectType.Board)
                {
                    if (handleThing.CompareTag("Ingredient"))
                    {
                        Collider.GetComponent<Object>().onSomething = true;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().isOnDesk = true;
                        handleThing.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().IngredientAuto(transform.parent.parent, transform.parent.parent.GetChild(1).localPosition, handleThing.transform.GetChild(0).GetComponent<Handle>().hand);
                    }
                }
                else if (Collider.GetComponent<Object>().type == Object.ObjectType.Craft)
                {
                    if (handleThing.CompareTag("Ingredient"))
                    {
                        Collider.GetComponent<Object>().onSomething = true;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().isOnDesk = true;
                        handleThing.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                        handleThing.transform.GetChild(0).GetComponent<Handle>().IngredientAuto(transform.parent.parent.parent.parent, transform.parent.localPosition, handleThing.transform.GetChild(0).GetComponent<Handle>().hand);
                    }
                    else //접시
                    {
                        if (Collider.GetComponent<Object>().type != Object.ObjectType.Board)
                        {
                            Collider.GetComponent<Object>().onSomething = true;
                            handleThing.transform.GetChild(0).GetComponent<Handle>().isOnDesk = true;
                            handleThing.transform.GetChild(0).GetComponent<Handle>().PlayerHandleOff(transform.parent.parent.parent.parent, transform.parent.localPosition);
                        }

                    }
                }
            }
        }
    }
}

 

3. 메뉴

(1) Scriptable Object

- 각 메뉴의 이름,  ingredient 종류들, 가격, 종료까지 걸리는 시간 등을 Scriptable Object를 만들어 data를 관리하도록 했다

이런식으로 필요한 이미지들과 아이콘까지 넣어줫따

 

(2) GameManager에 들어간 메뉴들 중 랜덤으로 골라서 뜨게하는 MakeOrder

이 만든 친구들을 이제 올려줘야 되는데

각 스테이지마다 존재하는 gamemanager에 

아래처럼 scriptable Object를 받는 변수를 만들어 줘서 넣어줬다.

넣어준 개수만큼 random 돌려서 메뉴들 중 하나를 선택해준다

 

 

(3) 주문서 UI들 이동하다가 멈추고 정렬하는,,,

주문서 ui들 만들어 둔 것들을 이용할 거다.

오브젝트 풀링을 이용해 만들었고, 꺼져있는 애를 찾아서 make Order로 선정된 메뉴의 ui와 시간 등을 연동시킨다

 

4. 게임 시작 전 일시정지된 상태로 Ready Go

첫 시작은 아무 이동도 없고 시간이 멈춘채로  Ready Go 나오는데

이를 위해 Time.TimeScale = 0으로 시작해서

Update문을 통해 (시간이 멈춰도 진행됨) 시간을 세서 Scale 조정하는 Coroutine 짜서 시작

 

5. Slider들 (메뉴 주문서, 시간 UI) 색 그라데이션 초록 -> 노랑 -> 빨강 

-> Lerp 함수를 써서 성공했지롱

 

6. 맞는 주문 내면 코인 연동

7. autoTrash 기능 

-> 자동 정렬 기능처럼 capsule collider isTrigger 처리해주고 닿으면 버려준다

 

8. 텍스트 둠칫둠칫 및 색깔 바꿈

(얘도 Lerp랑 Coroutine 사용)

 

9. 바닥에 버리는 경우 추가

손에 들고있고, 테이블 위에 재료가 있는데도 누르면 바닥에 놔둠

728x90