Project/Alice Project

Cat Hunting

Red_Horse 2022. 2. 13. 12:00

Cat Hunting Play Flow

private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Cat_Attack_small")
        {
            Destroy(other.gameObject);
            count.damage_count++;
        }
    }

고양이가 공격을 당한 경우 공격 횟수가 증가한다. ( 공격 오브젝트 Tag == "Cat_Attack_small")

 

고양이 Attack 인식 범위

 

IEnumerator attack_ready()
        {
            if (damage_count < 3) // 일반 공격
            {
                angry_cat_face.SetActive(false);
                angry_cat_arm.SetActive(false);
                mordern_cat_face.SetActive(true);
                mordern_cat_arm.SetActive(true);
                Attack_Point(mordern_cat_face, mordern_cat_arm);
                yield return new WaitForSeconds(1f);
                Attack_Modern_face();
                yield return new WaitForSeconds(3f);
                Attack_Modern_arm();
                yield return new WaitForSeconds(0.5f);
                attack_modern_zone.enabled = true;
                yield return new WaitForSeconds(0.3f);
                mordern_hit_event.SetActive(true);
                attack_item_move(10f);
                yield return new WaitForSeconds(2f);
                mordern_hit_event.SetActive(false);
                attack_modern_face.enabled = false;
                attack_modern_arm.enabled = false;
                attack_modern_zone.enabled = false;
            }
            else if (damage_count >= 3) // 강력한 공격
            {
                mordern_cat_face.SetActive(false);
                mordern_cat_arm.SetActive(false);
                angry_cat_face.SetActive(true);
                angry_cat_arm.SetActive(true);
                Attack_Point(angry_cat_face, angry_cat_arm);
                yield return new WaitForSeconds(1f);
                Attack_Angry_face();
                yield return new WaitForSeconds(2f);
                Attack_Angry_arm();
                yield return new WaitForSeconds(0.5f);
                attack_modern_zone.enabled = true;
                yield return new WaitForSeconds(0.8f);
                angry_hit_event.SetActive(true);
                attack_item_move(30f);
                yield return new WaitForSeconds(3f);
                angry_hit_event.SetActive(false);
                attack_angry_face.enabled = false;
                attack_angry_arm.enabled = false;
                attack_angry_zone.enabled = false;
                damage_count = 0;
                Drop();
            }

            if (item_attack_count >= 3)
            {
                mordern_cat_face.SetActive(false);
                angry_cat_face.SetActive(true);
                Attack_Angry_face();
                yield return new WaitForSeconds(2f);
                Misson_Clear();
            }

            StartCoroutine(attack_ready());
        }

 

공격실행 반복 메서드

 - 공격하는 고양이의 오브젝트를 나누어 공격 실행시 해당 공격에 맞는 고양이가 나타나서 공격하는 방식

 - 매 공격마다 땅에 떨어진 메인 오브젝트 개수를 확인하여 게임 클리어를 확인한다.

 - 고양이가 3번의 공격을 받은 경우 강력한 공격이 실행된다.

 

void Attack_Point(GameObject body, GameObject arm)
        {
            int random_point = Random.Range(2, 8) * 10;
            Vector3 cat_body_point = body.transform.position;
            Vector3 cat_arm_point = arm.transform.position;
            body.transform.position = new Vector3(random_point-20, cat_body_point.y, cat_body_point.z);
            arm.transform.position = new Vector3(random_point, cat_arm_point.y, cat_arm_point.z);
        }

고양이 오브젝트의 몸과 손을 받아와서 매 공격실행시 위치를 Random으로 적용한다.

 - 고양이의 몸은 고양이의 손의 위치에서 -20만큼 떨어진 곳에서 활성화 된다.(일정한 간격 유지)

 

 

void Drop()
        {
            area.enabled = true;

            count = Random.Range(15, max_intantiate);
            for(int i = 0; i < count; ++i)
            {
                Spawn();
            }
            area.enabled = false;
        }

        void Spawn()
        {
            int selection = Random.Range(0, Drop_Prefab.Length);

            GameObject selectedPrefab = Drop_Prefab[selection];

            Vector3 spawnPos = GetRandomPosition();

            GameObject instance = Instantiate(selectedPrefab, spawnPos, Quaternion.identity); // 오브젝트를 생성(동적할당)
            create_item.Add(instance);
        }

        private Vector3 GetRandomPosition()
        {
            Vector3 basePosition = area.transform.position;
            Vector3 size = area.size;

            float posX = basePosition.x + Random.Range(-size.x / 2f, size.x / 2f);
            float posY = basePosition.y + Random.Range(-size.y / 2f, size.y / 2f);
            float posZ = basePosition.z + Random.Range(-size.z / 2f, size.z / 2f);

            Vector3 spawnPos = new Vector3(posX, posY, posZ);

            return spawnPos;
        }

공격 아이템 생성 메서드

 - Drop. 생성할 아이템의 개수를 정한다. (개수만큼 반복실행)

 - Spawn. 생성할 아이템을 선택하고 동적할당을 처리한다.

 - GetRandomPosition. 아이템이 생성될 위치를 선택한다. (오브젝트의 크기를 활용)

 

아이템 생성 위치 범위 설정

 

 

 

void attack_item_move(float move)
        {
            foreach (GameObject o in drop_attack_item)
            {
                o.transform.position = new Vector3(o.transform.position.x, o.transform.position.y, (Mathf.Lerp(o.transform.position.z, transform.position.z - move, Time.deltaTime * 10f)));
            }
        }

 

떨어지는 메인 오브젝트의 위치변경

 - 메인 오브젝트들이 저장되어 있는 배열을 반복실행하여 각각의 오브젝트들을 받아온 움직임 값만큼 이동시킨다.

 

메인 오브젝트들이 떨어지는 위치

메인 오브젝트들에게 Tag를 주어 해당 오브젝트와 충돌이 일어나면 메인 오브젝트가 떨어진 것으로 인식

 

private ParticleSystem partSystem;

    void Start()
    {
        partSystem = gameObject.GetComponent<ParticleSystem>();
        partSystem.enableEmission = false;
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Cat")
            StartCoroutine(Start_particle());
    }
    
    IEnumerator Start_particle()
    {
        partSystem.enableEmission = true;
        yield return new WaitForSeconds(1.0f);
        partSystem.enableEmission = false;

공격 오브젝트에 파티클을 넣어놓고 Cat과 충돌을 하였을때 충돌 파티클 실행

 

 

 

Cat Attack particle

 

 

Cat Attack

 

'Project > Alice Project' 카테고리의 다른 글

Window Mission  (0) 2022.02.14
Spider Hunting  (0) 2022.02.13
Inventory make  (0) 2022.02.13