protected override void HandleDamage(Collider2D other)
    {
        GameObject hit         = other.gameObject;
        Health     health      = hit.GetComponent <Health>();
        Breakable  breakHealth = hit.GetComponent <Breakable>();

        if (health != null)
        {
            health.Damage(damage);
            health.lastHit = playerIndex;
            Destroy(gameObject);
        }
        else if (breakHealth != null)
        {
            breakHealth.Damage(damage);
            Destroy(gameObject);
        }

        this.GetComponent <Collider2D>().isTrigger = false;

        source.Play();
        numOfBounces++;

        if (numOfBounces >= maxNumOfBounces)
        {
            Destroy(gameObject);
        }
    }
Ejemplo n.º 2
0
    private void DoDamage(GameObject damagedPlayer, int damage)
    {
        Health    health      = damagedPlayer.GetComponent <Health>();
        Breakable breakHealth = damagedPlayer.GetComponent <Breakable>();

        if (health != null)
        {
            //Giving lastHit the playerIndex of the shooting player
            health.lastHit = PlayerID;
            health.ResetLastHitTimer();
            health.Damage(damage);
        }
        else if (breakHealth != null)
        {
            breakHealth.Damage(damage);
        }
    }
Ejemplo n.º 3
0
    protected override void HandleDamage(Collider2D other)
    {
        GameObject hit         = other.gameObject;
        Health     health      = hit.GetComponent <Health>();
        Breakable  breakHealth = hit.GetComponent <Breakable>();

        if (health != null)
        {
            //Giving lastHit the PlayerID of the shooting player
            health.lastHit = PlayerID;
            health.ResetLastHitTimer();
            health.Damage(Stats._projectileDamage);

            Destroy(gameObject);
        }
        else if (breakHealth != null)
        {
            breakHealth.Damage(Stats._projectileDamage);

            Destroy(gameObject);
        }
        else
        {
            // Nothing with health hit
            RaycastHit2D rayCast;
            Vector2      vel = GetComponent <Rigidbody2D>().velocity;
            rayCast = Physics2D.Raycast(transform.position, vel);

            Vector2 reflected = Vector2.Reflect(vel, rayCast.normal);
            reflected.Normalize();
            float angle = Mathf.Atan2(reflected.y, reflected.x);

            Vector2 newPos   = rayCast.point;
            Vector3 newAngle = new Vector3(0, 0, Mathf.Rad2Deg * angle);

            // Debug.DrawLine(newPos, reflected * 1 + newPos, Color.red, 2);
            // Debug.DrawLine(newPos, -vel.normalized * 1 + newPos, Color.red, 2);

            // Don't trigger behaviour, instead bounce.
            transform.position           = newPos;
            transform.rotation           = Quaternion.Euler(newAngle);
            projectileRigidBody.velocity = transform.right * _currentSpeed;
        }
    }
    protected virtual void HandleDamage(Collider2D other)
    {
        GameObject hit         = other.gameObject;
        Health     health      = hit.GetComponent <Health>();
        Breakable  breakHealth = hit.GetComponent <Breakable>();

        if (health != null)
        {
            //Giving lastHit the PlayerID of the shooting player
            health.lastHit = PlayerID;
            health.ResetLastHitTimer();
            health.Damage(Stats._projectileDamage);
        }
        else if (breakHealth != null)
        {
            breakHealth.Damage(Stats._projectileDamage);
        }
        else
        {
            // Nothing with health hit
            RaycastHit2D rayCast;
            Vector2      vel = GetComponent <Rigidbody2D>().velocity;
            rayCast = Physics2D.Raycast(transform.position, vel);

            Vector2 reflected = Vector2.Reflect(vel, rayCast.normal);
            reflected.Normalize();
            float angle = Mathf.Atan2(reflected.y, reflected.x);

            Vector2 newPos   = rayCast.point;
            Vector3 newAngle = new Vector3(0, 0, Mathf.Rad2Deg * angle);

            // Debug.DrawLine(newPos, reflected * 1 + newPos, Color.red, 2);
            // Debug.DrawLine(newPos, -vel.normalized * 1 + newPos, Color.red, 2);

            if (OnTriggerBehaviour != null)
            {
                OnTriggerBehaviour(newPos, newAngle, this, other);
            }
        }

        Destroy(gameObject);
    }
    protected virtual void HandleDamage(Collider2D other)
    {
        GameObject hit         = other.gameObject;
        Health     health      = hit.GetComponent <Health>();
        Breakable  breakHealth = hit.GetComponent <Breakable>();

        if (health != null)
        {
            //Giving lastHit the playerIndex of the shooting player
            health.lastHit = playerIndex;
            health.ResetLastHitTimer();
            health.Damage(damage);
        }
        else if (breakHealth != null)
        {
            breakHealth.Damage(damage);
        }

        Destroy(gameObject);
    }
    protected override void Shoot()
    {
        RaycastHit2D hit = Physics2D.Raycast(bulletSpawn.position, this.transform.right);

        lineRenderer.enabled = true;
        lineRenderer.SetPosition(0, bulletSpawn.transform.position);
        lineRenderer.SetPosition(1, hit.point);

        if (hit.collider != null)
        {
            Health    health      = hit.transform.GetComponent <Health>();
            Breakable breakHealth = hit.transform.GetComponent <Breakable>();
            if (health != null)
            {
                health.Damage(bulletDamage);
            }
            else if (breakHealth != null)
            {
                breakHealth.Damage(bulletDamage);
            }
        }
    }