Ejemplo n.º 1
0
    void useWeapon()
    {
        //playerPlatformer.setAnimationState(PlayerPlatformerController.MovementState.Attacking);
        animator.SetTrigger("Attack");

        if (weapon <= Weapons.Sword)
        {
            MeleeHandler mhandler = gameObject.GetComponentInChildren <MeleeHandler>();
            if (mhandler.hit())
            {
                Collider2D enemy = mhandler.enemy();
                if (enemy.tag == "Enemy")
                {
                    enemy.gameObject.GetComponent <HealthController>().healthSub(25);
                }
            }

            return;
        }

        SpriteRenderer sr        = gameObject.GetComponentInChildren <SpriteRenderer>();
        int            direction = -1;

        if (!sr.flipX)
        {
            direction = 1;
        }

        Vector2 bulletSpawnPos = transform.position;

        bulletSpawnPos.x += direction * bulletXOffset;
        // coordinate bullet spawn with the sprite
        bulletSpawnPos.y -= 0.3f;

        int numBullets = 1;

        if (weapon == Weapons.Shotgun)
        {
            numBullets = 2;
        }

        for (int i = 0; i < numBullets; i++)
        {
            bulletSpawnPos.y += 0.2f * i;
            GameObject bullet      = Instantiate(bullets[(int)weapon - nonBulletWeps], bulletSpawnPos, Quaternion.identity);
            float      bulletSpeed = bullet.GetComponent <BulletController>().speed;
            Vector2    forceVector = new Vector2(bulletSpeed * direction, 0);
            Vector2    randomizer  = new Vector2(
                UnityEngine.Random.Range(-bulletSpreadRange, bulletSpreadRange),
                UnityEngine.Random.Range(-bulletSpreadRange, bulletSpreadRange)
                );

            Rigidbody2D brb = bullet.GetComponent <Rigidbody2D>();
            brb.AddForce(
                forceVector + randomizer

                );
        }
    }
Ejemplo n.º 2
0
    public IEnumerator DelayedDamage(object[] args)
    {
        float delayTime = (float)args[0];

        yield return(new WaitForSeconds(delayTime)); // lmao this will be fine

        Player       player         = (Player)args[1];
        MeleeHandler m_meleeHandler = (MeleeHandler)args[2];

        float distanceFromPlayer = (player.transform.position - transform.position).magnitude;

        if (distanceFromPlayer - m_meleeHandler.GetAttackRange() <= 0f) // Check if in range BEFORE appling damage
        {
            player.m_healthHandler.Damage(m_meleeHandler.GetMeleeDamage());
            StartCoroutine(player.m_audioHandler.PlayDamageSound());
            StartCoroutine(player.m_healthHandler.ApplyDamageEffect(player.GetComponent <SpriteRenderer>()));
            player.m_movementHandler.Knockback(1000f, (player.transform.position - transform.position), player.GetComponent <Rigidbody2D>());
        }
    }