Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        // 충돌한 오브젝트에 DamageZone 태그가 있는가?
        if (other.CompareTag("DamageZone"))
        {
            // 그렇다면 플레이어의 HP를 감소시킨다
            HealthController.Instance.Damage(30f);
            // 적을 제거해서 뷰포트 밖으로 나가지 못하게 한다
            StartCoroutine(Kill());
            return;
        }
        // 충돌한 게임오브젝트에 있는 ActiveBarrierController 컴포넌트를 저장한다
        ActiveBarrierController barrierController = other.GetComponent <ActiveBarrierController>();

        // 충돌한 오브젝트가 장애물이면 HitByEnemy 함수를 호출하다
        if (barrierController != null)
        {
            barrierController.HitByEnemy(this);
        }
    }
Ejemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //Is the collided object a DamageZone?
        if (other.CompareTag("DamageZone"))
        {
            //In that case, hurt the player
            HealthController.Instance.Damage(12f);
            giveReward = false;
            byPlayer   = false;
            StartCoroutine(Kill());
            return;
        }
        //Store the collided object's ActiveBarrierController
        ActiveBarrierController barrierController = other.GetComponent <ActiveBarrierController>();

        //If it has none, it's not a Barrier - don't go further
        if (barrierController == null)
        {
            return;
        }
        //Else, call the ActiveBarrier's method for collision handling
        barrierController.HitByEnemy(this);
    }