Ejemplo n.º 1
0
    void shoot()
    {
        if (Mathf.Abs(orbiter.targetRadius - orbiter.radius) > 0.05f)
        {
            return;
        }

        if (ammoScript.currentAmmo > 0)
        {
            FindObjectOfType <AudioManager>().Play("ShootingBullet", this.gameObject);
            GameObject bullet = Instantiate(bulletPrefab);
            bullet.transform.position = transform.position;

            var angle = Mathf.Atan2(transform.position.y, transform.position.x) * Mathf.Rad2Deg;
            bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            Orbiter bulletOrbiter = bullet.GetComponent <Orbiter>();
            bulletOrbiter.radius        = orbiter.radius;
            bulletOrbiter.targetRadius  = orbiter.radius;
            bulletOrbiter.speed         = orbiter.speed * 2;
            bulletOrbiter.moveClockwise = orbiter.moveClockwise;
            bulletOrbiter.orbit(50);
            ammoScript.consumeAmmo();
        }
    }