Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Collider2D[] results = new Collider2D[64];

        int nCollisions = Physics2D.OverlapCollider(damageArea, contactFilter, results);

        if (nCollisions > 0)
        {
            for (int i = 0; i < nCollisions; i++)
            {
                Collider2D otherCollider = results[i];

                HP hp = otherCollider.GetComponent <HP>();

                if (hp)
                {
                    if (gameObject.name == "Heal")
                    {
                        hp.HealDamage();
                    }
                    else
                    {
                        hp.DealDamage(damage);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        GameObject[] enemyGrounds   = GameObject.FindGameObjectsWithTag("EnemyGround");
        GameObject[] enemyFlys      = GameObject.FindGameObjectsWithTag("EnemyFly");
        float        shortDistanceG = Mathf.Infinity;
        float        shortDistanceF = Mathf.Infinity;
        GameObject   closeEnemyG    = null;
        GameObject   closeEnemyF    = null;

        foreach (GameObject enemyGround in enemyGrounds)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemyGround.transform.position);
            if (shortDistanceG > distanceToEnemy)
            {
                shortDistanceG = distanceToEnemy;
                closeEnemyG    = enemyGround;
            }
        }

        foreach (GameObject enemyFly in enemyFlys)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemyFly.transform.position);
            if (shortDistanceF > distanceToEnemy)
            {
                shortDistanceF = distanceToEnemy;
                closeEnemyF    = enemyFly;
            }
        }

        if (closeEnemyG != null && shortDistanceG <= 5)
        {
            target = closeEnemyG.transform;
        }
        else if (closeEnemyF != null && shortDistanceF <= 5)
        {
            target = closeEnemyF.transform;
        }
        else
        {
            target = null;
        }

        if (target == null)
        {
            return;
        }

        if (Time.time - timer > 0.3f)
        {
            HP hp = target.GetComponent <HP>();
            hp.DealDamage(20);
            timer = Time.time;
        }
    }
Esempio n. 3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if ((tag == collision.tag) || (walltag == collision.tag))
        {
            Destroy(gameObject);

            HP hp = collision.GetComponent <HP>();

            if (hp)
            {
                hp.DealDamage(damage, Adamage);
            }

            Player_Mouvement player = collision.GetComponent <Player_Mouvement>();

            if ((player) && (gameObject.tag == "MacDo"))
            {
                Shoot gun = weapon.GetComponent <Shoot>();
                gun.NewWeapon(2);
            }

            else if ((player) && (gameObject.tag == "Shootgun"))
            {
                Shoot gun = weapon.GetComponent <Shoot>();
                gun.NewWeapon(1);
            }

            BossCinematic cinematic = gameObject.GetComponent <BossCinematic>();

            if (cinematic)
            {
                cinematic.Cutscene();
            }

            BossFightStarts fight = gameObject.GetComponent <BossFightStarts>();

            if (fight)
            {
                fight.Cutscene();
            }
        }
    }
Esempio n. 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if ((tag == collision.tag) || (walltag == collision.tag))
        {
            HP hp = collision.GetComponent <HP>();

            if (hp)
            {
                hp.DealDamage(damage, Adamage);
            }

            MoveForward returning = gameObject.GetComponent <MoveForward>();

            if (returning)
            {
                returning.Return();
            }
        }

        if (enemytag == collision.tag)
        {
            Destroy(gameObject);
        }
    }