コード例 #1
0
ファイル: Bazooka.cs プロジェクト: DavidBjorkberg/Unity_FPS
 public override void Shoot(Vector3 pointA, Vector3 pointB, Vector3 pointC, Collider pointBCollider)
 {
     if (curAmmo > 0 && timeSinceLastShot > fireRate)
     {
         curAmmo--;
         GameManager.instance.UpdateAmmoBar(maxAmmo, curAmmo);
         timeSinceLastShot = 0;
         BazookaBullet instantiatedBullet = Instantiate(bullet, gunpoint.position, Quaternion.identity);
         instantiatedBullet.Initialize(pointA, pointB, pointC, damage, pointBCollider, true);
     }
 }
コード例 #2
0
    public override bool Shoot(bool isVampire = false, bool isQuick = false)
    {
        if (ammo > 0 && Time.time > nextFire)
        {
            // Create a bullet.
            BazookaBullet bulletClone = Instantiate(bullet, spawnPoint.position, transform.rotation) as BazookaBullet;
            bulletClone.SetDamage(baseDamage, isVampire);
            bulletClone.OnTargetReached = HealPlayer;   // Register the vampibot delegate.

            // Adjust the direction of the bullet.
            RaycastHit hit;
            if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out hit, 500.0f))
            {
                // If the raycast impacts, shoot exactly in that direction.
                bulletClone.transform.LookAt(hit.point);
            }
            else
            {
                // If the raycast does not impact, shoot to the point in the perpendicular direction of the camera.
                bulletClone.transform.LookAt(spawnPoint.position + cameraTransform.forward * 500.0f);
            }

            // Adjust the dispersion.
            Vector3 euler = bulletClone.transform.localRotation.eulerAngles;
            euler.x += Random.Range(-5.0f + accuracyCapacity * 4.0f, 5.0f - accuracyCapacity * 4.0f);
            euler.y += Random.Range(-5.0f + accuracyCapacity * 4.0f, 5.0f - accuracyCapacity * 4.0f);
            bulletClone.transform.localRotation = Quaternion.Euler(euler);

            // Adjust the bullet speed taking in count the power.
            bulletClone.SetSpeed(defaultSpeed + power * 0.5f);

            // We lose power each time we shoot.
            power -= powerLossPerShot;
            if (power < 0)
            {
                power = 0;
            }

            if (isQuick)
            {
                nextFire = Time.time + fireRate * 0.5f;
            }
            else
            {
                nextFire = Time.time + fireRate;
            }

            ammo--;
            nextRecharge = Time.time + rechargeRate;
            return(true);
        }
        return(false);
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            if (_bazookaBullet != null && _firePoint != null && shooter != null)
            {
                GameObject    bbullet  = Instantiate(_bazookaBullet, _firePoint.position, _firePoint.rotation) as GameObject;
                BazookaBullet babullet = bbullet.GetComponent <BazookaBullet>();
                player.enabled = false;

                if (shooter.transform.localRotation.y < 0f)
                {
                    babullet.direction = Vector2.left;
                }
                else
                {
                    babullet.direction = Vector2.right;
                }
            }
        }
    }
コード例 #4
0
    // Update is called once per frame
    public void ShootBazooka()
    {
        if (_firePoint != null && Time.time > nextFire && _bazookaBullet != null)
        {
            nextFire = Time.time + fireRate;

            if (_bazookaBullet != null && _firePoint != null && shooter != null)
            {
                GameObject    bbullet  = Instantiate(_bazookaBullet, _firePoint.position, _firePoint.rotation) as GameObject;
                BazookaBullet babullet = bbullet.GetComponent <BazookaBullet>();
                player.enabled = false;
                bbullet.GetComponent <Rigidbody2D>().AddForce(new Vector3(1, 0, 0) * 20f, ForceMode2D.Impulse);
                if (shooter.transform.localRotation.y < 0f)
                {
                    babullet.direction = Vector2.left;
                }
                else
                {
                    babullet.direction = Vector2.right;
                }
            }
        }
    }