Example #1
0
    protected override void Attack()
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            int     angle = 25;
            Vector3 pushForce;
            do
            {
                pushForce = GetBallisticVelocity((target.position - transform.position).normalized * 10000f, angle);
                angle--;
            } while (float.IsNaN(pushForce.x) || float.IsNaN(pushForce.y) || float.IsNaN(pushForce.z));

            if (angle <= 0)
            {
                return;
            }
            target.gameObject.GetComponent <Rigidbody>().AddForce(pushForce, ForceMode.Impulse);
            target.GetComponent <BarbieLife>().decreaseLife(1);

            SoundOnAttack soa = GetComponent <SoundOnAttack>();

            if (soa != null)
            {
                soa.Play();
            }
        }
    }
    protected override void Attack()
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            Vector3    normalizedDirection = (target.position - transform.position).normalized;
            GameObject projectile          = GameObject.Instantiate(m_projectile, transform.position + normalizedDirection * 2f, transform.rotation) as GameObject;
            Rigidbody  rb = projectile.GetComponent <Rigidbody>();

            Vector3 ballisticVelocity = GetBallisticVelocity(target.position, RandomDevice.NextInt(15, 60));

            rb.AddForce(ballisticVelocity, ForceMode.Impulse);

            SoundOnAttack soa = GetComponent <SoundOnAttack>();

            if (soa != null)
            {
                soa.Play();
            }
        }
    }