예제 #1
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);
        }
    }
    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);
        }
    }