/// <summary>
    /// Shoots flare, deducts player's energy accordingly and
    /// zooms out camera to see more environment around player.
    /// </summary>
    private void ShootFlare()
    {
        player.LightEnergy.Deplete(flareEnergyCost);
        // Apply recoil in the opposite direction the flare was shot
        rigidbody.AddForce(-flareSpawnObject.right * recoilForce, ForceMode.Impulse);
        controllerRumble.ShotFlare();   // Rumble the controller
        timer = 0.0f;
        flareSound.ShootFlareSound();

        //reset all values for the zoom whenever player fires a flare
        if (smoothCamera != null)
        {
            smoothCamera.MaxZoomOut();
            smoothCamera.ResetTimer();
        }
    }
Пример #2
0
    void Update()
    {
        bool ready = false;

        if (timer < cooldownTime)
        {
            timer += Time.deltaTime;
        }
        else
        {
            ready = true;
        }
        if (Input.GetButtonDown("UseFlare"))
        {
            if (ready)
            {
                float cost = flareEnergyCost * flareCostPercentage;
                if ((lightSource.LightEnergy.CurrentEnergy > (flareEnergyCost + cost)))
                {
                    flare = (GameObject)Instantiate(flareObject, flareSpawnObject.position, flareSpawnObject.rotation);
                    lightSource.LightEnergy.Deplete(flareEnergyCost);
                    // Apply recoil in the opposite direction the flare was shot
                    rigidbody.AddForce(-flareSpawnObject.right * recoilForce, ForceMode.Impulse);
                    controllerRumble.ShotFlare();   // Rumble the controller
                    timer      = 0.0f;
                    flareSound = new FlareSound(flare);
                    flareSound.ShootFlareSound();

                    //reset all values for the zoom whenever player fires a flare
                    if (smoothCamera != null)
                    {
                        smoothCamera.FlareShoot();
                        smoothCamera.ResetTimer();
                    }
                }
            }
            else
            {
                playerSound.InsufficientEnergySound();
            }
        }
        if (flare != null)
        {
            flareDistance = Vector3.Distance(flare.transform.position, player.position);
            flareSound.SetFlareDistance(flareDistance);
        }
    }