Exemplo n.º 1
0
    private void ShootCollisionCheck()
    {
        Vector2 direction = Vector2.right;

        if (GetComponent <Movement>())
        {
            if (GetComponent <Movement>().direction == Movement.Direction.Left)
            {
                direction = Vector2.left;
            }
        }
        RaycastHit2D hit = Physics2D.BoxCast(transform.position, Vector2.one, 0, direction, 200, _collision.collisionLayer);

        if (hit)
        {
            Damage damage = hit.collider.GetComponent <Damage>();
            Stun   stun   = hit.collider.GetComponent <Stun>();
            if (damage)
            {
                damage.ExecuteDamage(attack.GetDamageAmount(), null);
                Object blood = Instantiate(damage.bloodShoot, hit.point, Quaternion.identity);
                if (transform.localScale.x < 0)
                {
                    ((GameObject)blood).transform.Rotate(0, 180, 0);
                }
            }
            if (stun)
            {
                stun.GetStunned(stunAmount: 0.7f, power: Stun.Power.Shoot);
            }
            if (bulletSpark)
            {
                GameObject instance = Instantiate(bulletSpark);
                instance.transform.position = new Vector3(hit.point.x, hit.point.y, -35);
                if (transform.localScale.x > 0)
                {
                    Vector3 euler = instance.transform.localEulerAngles;
                    euler.y = 180;
                    instance.transform.localEulerAngles = euler;
                }
                if (!hit.collider.tag.Contains("Obstacle"))
                {
                    instance.transform.FindContainsInChildren("Wood").SetActive(false);
                }
            }
        }
    }
Exemplo n.º 2
0
    private void ShootCollisionCheck()
    {
        Vector2 direction = Vector2.right;

        if (GetComponent <Movement>())
        {
            if (GetComponent <Movement>().direction == Movement.Direction.Left)
            {
                direction = Vector2.left;
            }
        }
        Vector2      size = new Vector2(1, 1);
        RaycastHit2D hit  = Physics2D.BoxCast(transform.position, size, 0, direction, 200, _collision.collisionLayer);

        if (hit)
        {
            Damage damage = hit.collider.GetComponent <Damage>();
            Stun   stun   = hit.collider.GetComponent <Stun>();
            if (damage)
            {
                damage.ExecuteDamage(attack.GetDamageAmount(), null);
                Object blood = Instantiate(damage.bloodShoot, hit.point, Quaternion.identity);
                if (transform.localScale.x < 0)
                {
                    ((GameObject)blood).transform.Rotate(0, 180, 0);
                }
            }
            if (stun)
            {
                stun.GetStunned(stunAmount: 0.7f, power: Stun.Power.Shoot);
            }
            if (bulletSpark)
            {
                GameObject instance = Instantiate(bulletSpark);
                instance.transform.position = new Vector3(hit.point.x, hit.point.y, -35);
                if (transform.localScale.x > 0)
                {
                    Vector3 euler = instance.transform.localEulerAngles;
                    euler.y = 180;
                    instance.transform.localEulerAngles = euler;
                }
                if (!hit.collider.tag.Contains("Obstacle"))
                {
                    instance.transform.FindContainsInChildren("Wood").SetActive(false);
                }
            }
        }
        base.PerformLightAttack();

        //Enable one use weapons for the Player
        if (gameObject.transform.name == "Player")
        {
            Destroy(gameObject.transform.FindContainsInChildren("Musket"));
            if (GetComponent <PlayerMotor>().savedWeapon)
            {
                gameObject.GetComponent <Attack>().SetWeapon(GetComponent <PlayerMotor>().savedWeapon);
                GetComponent <PlayerMotor>().savedWeapon.transform.gameObject.SetActive(true);
            }
            else
            {
                gameObject.GetComponent <Attack>().SetWeapon(gameObject.GetComponent <Weapon>());
            }
        }
    }