Ejemplo n.º 1
0
    void FirePrimary()
    {
        bool canfire = ((energyController.CurrentEnergy > PrimaryEnergyConsumption) && _canFirePrimary);


        if (canfire)
        {
            GameObject   bullet      = (GameObject)GameObject.Instantiate(PrimaryAmmo, transform.position + transform.forward * 3, Quaternion.identity);
            BulletScript bController = (BulletScript)bullet.GetComponent <BulletScript>();

            var shootPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, shootDistance);
            shootPosition = Camera.main.ScreenToWorldPoint(shootPosition);

            // GameObject player = GameObject.FindGameObjectWithTag("Player");



            bullet.transform.LookAt(shootPosition);

            bController.fire();

            if (!_audioSource.isPlaying)
            {
                _audioSource.Play();
            }

            energyController.decreaseEnergy(PrimaryEnergyConsumption);

            //rBullet.AddForce(firingSpeed * player.transform.forward);

            _canFirePrimary = false;
        }
    }
Ejemplo n.º 2
0
    void fire()
    {
        bool canfire = energyController.CurrentEnergy > energyConsumption;


        if (fireEnabled && canfire)
        {
            GameObject   bullet      = (GameObject)GameObject.Instantiate(ammo, transform.position + transform.forward * 3, Quaternion.identity);
            BulletScript bController = (BulletScript)bullet.GetComponent <BulletScript>();

            var shootPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, shootDistance);
            shootPosition = Camera.main.ScreenToWorldPoint(shootPosition);

            GameObject player = GameObject.FindGameObjectWithTag("Player");

            bullet.transform.LookAt(shootPosition);

            bController.fire();


            //rBullet.AddForce(firingSpeed * player.transform.forward);

            fireEnabled = false;
        }

        energyController.decreaseEnergy(energyConsumption);
    }