Beispiel #1
0
    private void HitTarget(RaycastHit hitInfo)
    {
        BaseDestructible target = hitInfo.transform.GetComponent <BaseDestructible>();

        if (target)
        {
            target.OnGettingHit(weaponProperties.damageType);
        }
    }
Beispiel #2
0
    void CmdFireShot(Vector3 clickPos)
    {
        Vector2 direction = clickPos - gunLocation.transform.position;

        if (Application.isEditor)
        {
            Debug.DrawRay(gunLocation.transform.position, direction, Color.red, 0.25f);
        }
        hit = Physics2D.Raycast(gunLocation.transform.position, direction, weapon.Range, toHit);

        if (!weapon.Shoot())
        {
            EmptyMagSound();
            return;
        }

        SoundBlast();
        MuzzleFlash();

        if (hit)
        {
            // Make sure we can't hit ourself
            if (hit.transform.gameObject.Equals(gameObject))
            {
                DebugConsole.Instance.Log("You hit yourself, doofus");
                return;
            }

            if (hit.transform.tag == "Player")
            {
                PlayerHealth hp = hit.transform.GetComponent <PlayerHealth>();
                hp.InflictDamage(weapon.Damage);
            }

            if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Wall"))
            {
                BaseDestructible hitObj = hit.transform.GetComponent <BaseDestructible>();
                if (hitObj)
                {
                    hitObj.OnHit(weapon.Damage);
                }
            }
        }
    }