示例#1
0
    void SkidSounds()
    {
        float maxSkid = (MaxSpeed / 2f);

        SkidAmount  = Mathf.Abs(transform.InverseTransformDirection(r.velocity).x);
        SkidAmount -= (MaxSpeed / 8f);        //making it less sensitive

        if (SkidAmount > maxSkid)
        {
            SkidAmount = maxSkid;
        }

        float alpha = Mathf.Lerp(0f, 1f, SkidAmount / maxSkid);

        float SpeedAlpha = r.velocity.magnitude / MaxSpeed;

        if (SpeedAlpha > 1f)
        {
            SpeedAlpha = 1f;
        }

        if (Brake)
        {
            ASC_Tires.SetVolume(Mathf.Lerp(0f, 1f, SpeedAlpha));
        }
        else
        {
            ASC_Tires.SetVolume(alpha);
        }
    }
示例#2
0
    public void Pickup()
    {
        if (!Locked && !PickedUp)
        {
            GetComponent <Collider>().isTrigger = true;

            this.transform.SetParent(Cam);
            this.transform.localPosition = new Vector3(0f, 0f, DistanceOffset);
            this.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);

            this.transform.GetChild(0).GetComponent <MeshRenderer>().material.SetFloat("_Unlit", 1f);

            PC.NoLook = true;
            PickedUp  = true;

            ASC.Sound = PickupSound;
            ASC.SetVolume(1f);
            ASC.Play();

            OnPickup.Invoke();
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = true;


            StartCoroutine(PutDown());
        }
    }
示例#3
0
    void MakeNoise()
    {
        if (ASC && !isSpeaking)
        {
            ASC.Sound = Noises[Random.Range(0, Noises.Count)];
            ASC.SetVolume(0.25f);

            ASC.Play();
        }
    }
示例#4
0
    IEnumerator ChangeChannel(int Index, bool Static)
    {
        RadioSwapping = true;

        if (Static)
        {
            ASC_Radio.SetVolume(0.5f);
            ASC_Radio.Sound = StaticSound;
            ASC_Radio.Play();
            yield return(new WaitForSeconds(1f));

            ASC_Radio.Stop();
        }

        PlaySong();

        yield return(new WaitForSeconds(0.25f));

        RadioSwapping = false;
    }
示例#5
0
    void WheelSkidSound()
    {
        float newVolume = 0;
        float newPitch  = 0;

        if (sidewaysSlip > 0.3f)
        {
            newVolume += sidewaysSlip;
            newPitch  += sidewaysSlip;
        }
        if (forwardSlip > 0.4f)
        {
            newVolume += forwardSlip;
            newPitch  += forwardSlip;
        }

        audioController.SetVolume(newVolume / 2);
        audioController.SetPitch(newPitch / 2);
    }
示例#6
0
    void Update()
    {
        RefreshLoopingAudioLevels();

        float SpeedAlpha = r.velocity.magnitude / VehicleMaxSpeed;

        if (SpeedAlpha > 1f)
        {
            SpeedAlpha = 1f;
        }

        ASC_Engine.SetPitch(Mathf.Lerp(PitchLow, PitchHigh, SpeedAlpha));
        ASC_Engine.SetVolume(1f);

        ASC_Road.SetVolume(Mathf.Lerp(0f, 0.25f, SpeedAlpha));

        ASC_Wind.SetPitch(SpeedAlpha);
        ASC_Wind.SetVolume(SpeedAlpha);
    }
示例#7
0
    public void BreakGlass()
    {
        ASC_FrontGlass.SetVolume(1f);
        ASC_SideGlass.SetVolume(1f);

        ASC_FrontGlass.Sound = BreakSound;
        ASC_SideGlass.Sound  = BreakSound;

        ASC_FrontGlass.Play();
        ASC_SideGlass.Play();

        Material[] Temp = new Material[Body.materials.Length];
        for (int i = 0; i < Temp.Length; i++)
        {
            Temp[i] = Body.materials[i];
        }

        Temp[4] = Broken_Glass;

        Body.materials = Temp;
    }
示例#8
0
 void PlayAmbient()
 {
     ASC_Ambient.SetVolume(1f);
     ASC_Ambient.Play();
 }
示例#9
0
 public void MakeSound()
 {
     ASC.Sound = MenuSound;
     ASC.SetVolume(0.2f);
     ASC.Play();
 }
示例#10
0
    void Update()
    {
        RefreshLoopingAudioLevels();

        if (!M.Paused)
        {
            if (!Frozen)
            {
                CameraControls();
                if (!M.C.Active)
                {
                    ZoomControls();

                    if (!RadioSwapping && CurrentStation != 0)
                    {
                        if (Input.mouseScrollDelta.y > 0f)
                        {
                            ChangeStation(true);
                        }

                        if (Input.mouseScrollDelta.y < 0f)
                        {
                            ChangeStation(false);
                        }
                    }
                }
            }

            if (Input.GetKeyDown("q") && !M.C.Active)
            {
                ASC_Misc.Sound = BrightsSound;
                ASC_Misc.SetVolume(1f);
                ASC_Misc.Play();
                Brights = !Brights;
            }

            if (Brights)
            {
                Headlight.intensity = BrightLight;
                Headlight.range     = BrightRange;
                BrightEffect();
            }
            else
            {
                Headlight.intensity = LowLight;
                Headlight.range     = LowRange;
            }

            float   ShakeAmount = Offroading ? 0.025f * (r.velocity.magnitude / MaxSpeed) : 0.005f * (r.velocity.magnitude / MaxSpeed);
            Vector3 ShakeVec    = new Vector3(Random.Range(-ShakeAmount, ShakeAmount), Random.Range(-ShakeAmount, ShakeAmount), Random.Range(-ShakeAmount, ShakeAmount));
            ToPitch.transform.localPosition = ShakeVec;

            SpeedDial.Value = r.velocity.magnitude;

            float SpeedAlpha = r.velocity.magnitude / MaxSpeed;
            if (SpeedAlpha > 1f)
            {
                SpeedAlpha = 1f;
            }

            ASC_Road.SetVolume(Offroading ? Mathf.Lerp(0f, 1f, SpeedAlpha) : Mathf.Lerp(0f, 0.25f, SpeedAlpha));
            ASC_OffRoad.SetVolume(Offroading ? Mathf.Lerp(0f, 1f, SpeedAlpha) : Mathf.Lerp(0f, 0.5f, SpeedAlpha));

            //ASC_Engine.SetVolume(Mathf.Lerp(0.5f, 1f, SpeedAlpha));
            ASC_Engine.SetPitch(Mathf.Lerp(PitchLow, PitchHigh, SpeedAlpha));

            SpeedAlpha -= 0.4f;
            if (SpeedAlpha < 0f)
            {
                SpeedAlpha = 0f;
            }
            ASC_Wind.SetPitch(SpeedAlpha);


            if (!ASC_Radio.AS.isPlaying && CurrentStation != 0 && !RadioSwapping)
            {
                PlaySong();
            }


            SkidSounds();
        }
    }
示例#11
0
    void CarControls()
    {
        if (!Frozen)
        {
            float Turn  = 0f;
            float Gas   = 0f;
            bool  Brake = false;

            Vector3 LookDir = Goal.position - this.transform.position;
            float   Angle   = Vector3.SignedAngle(LookDir, this.transform.forward, this.transform.up);

            float BlindDeadZone = 0f;
            if (Blinded)
            {
                BlindDeadZone = 10f;
                Blinded       = false;
                Enrage();
            }

            if (Mathf.Abs(Angle) > TurnDeadZone + BlindDeadZone)
            {
                if (Angle < -SteerAngleGoal) //Full Turn Right
                {
                    Turn = 1f;
                }
                else if (Angle > SteerAngleGoal) //Full Turn Left
                {
                    Turn = -1f;
                }

                if (Angle < 0f && Angle > -SteerAngleGoal)   //Adjust Turn Right
                {
                    Turn = Mathf.Lerp(0f, 1f, Angle / -SteerAngleGoal);
                }
                else if (Angle > 0f && Angle < SteerAngleGoal)  //Adjust Turn Left
                {
                    Turn = Mathf.Lerp(0f, -1f, Angle / SteerAngleGoal);
                }
            }


            float Distance = Vector3.Distance(this.transform.position, Goal.position);

            //Debug.Log(Distance);

            if (Distance < PositionDistanceGoal)
            {
                GetRoad();
            }

            if (Distance > ForgetDistance)
            {
                CurrentNode       = new Road.Node();
                CurrentNode.Index = -1;
                GetRoad();
            }


            //DetectDirection = (Goal.transform.position - this.transform.position).normalized;
            DetectDirection = Quaternion.Euler(0f, Turn * SteerAngleGoal, 0f) * transform.forward;
            Vector3 RayOrigin = this.transform.position + (this.transform.up * 0.75f) + (this.transform.forward * DetectStart);

            RaycastHit hit;
            if (Physics.Raycast(RayOrigin + (this.transform.right * .6f), DetectDirection, out hit, DetectDistance))
            {
                DetectAlpha = 1f;

                try
                {
                    if (hit.transform.GetComponent <Rigidbody>() != null)
                    {
                        DetectAlpha = Vector3.Distance(this.transform.position + (this.transform.up * 1f) + (this.transform.forward * DetectStart), hit.point) / DetectDistance;
                    }
                }catch {}
            }
            else
            {
                DetectAlpha = 1f;
            }

            float SecondDetect = 1f;

            if (Physics.Raycast(RayOrigin + (this.transform.right * -.6f), DetectDirection, out hit, DetectDistance))
            {
                try
                {
                    if (hit.transform.GetComponent <Rigidbody>() != null)
                    {
                        SecondDetect = Vector3.Distance(this.transform.position + (this.transform.up * 1f) + (this.transform.forward * DetectStart), hit.point) / DetectDistance;
                    }
                }catch {}
            }
            else
            {
                SecondDetect = 1f;
            }

            if (SecondDetect < DetectAlpha)
            {
                DetectAlpha = SecondDetect;
            }



            if (Mathf.Abs(Angle) > 90f)      //to turn around
            {
                //Debug.Log(Mathf.Abs(Angle));
                if (Mathf.Abs(Angle) > (180f - 25f))
                {
                    Turn = 0f;
                    Gas  = -1f;
                }
                else
                {
                    Turn = -Turn;
                    Gas  = -1f;
                }
            }
            else
            {
                float SpeedGoal =
                    (
                        CurrentRoad.Speedlimit +
                        DriverMaxSpeed +
                        (willTurn ? 5f - CurrentRoad.Speedlimit - DriverMaxSpeed : 0f) +
                        (Angry ? 5f : 0f)
                    );

                if (r.velocity.magnitude < SpeedGoal && Distance > PositionDistanceGoal) //stay at a decent speed
                {
                    Gas = Mathf.Lerp(0f, 1f, DetectAlpha / 1f);
                }

                if (r.velocity.magnitude > SpeedGoal)        //reverse if driving too fast
                {
                    Gas = -1f;
                }

                /*
                 * if(DetectAlpha < 0.15f && DetectAlpha > 0.1f)
                 * {
                 *  Brake = true;
                 * }*/
                if (DetectAlpha < 0.5f && r.velocity.magnitude > SpeedGoal / 2f)   //brake if going fast next to another car
                {
                    Brake = true;
                    ASC_Horn.SetVolume(1f);
                }
                else
                {
                    ASC_Horn.SetVolume(0f);
                }

                if (Angry)
                {
                    ASC_Horn.SetVolume(1f);
                }

                if (DetectAlpha < 0.25f && DetectAlpha > 0.1f && r.velocity.magnitude > 0f)   //brake to a stop
                {
                    Brake = true;
                }

                if (DetectAlpha > 0.1f && DetectAlpha < 0.25f)
                {
                    Waiting = true;
                }
                else
                {
                    Waiting = false;
                }

                if (willTurn && r.velocity.magnitude > (CurrentRoad.Speedlimit + DriverMaxSpeed))     //brake if speeding before turn
                {
                    Brake = true;
                }

                if (DetectAlpha < 0.1f)     //reverse if stuck
                {
                    Gas = -1f;
                }
            }

            CurrentSteeringAngle   = MaxSteeringAngle * Turn;
            FR_Collider.steerAngle = CurrentSteeringAngle;
            FL_Collider.steerAngle = CurrentSteeringAngle;

            if (!Brake)
            {
                FR_Collider.motorTorque = MotorForce * Gas;
                FL_Collider.motorTorque = MotorForce * Gas;

                FR_Collider.brakeTorque = 0f;
                FL_Collider.brakeTorque = 0f;
                BR_Collider.brakeTorque = 0f;
                BL_Collider.brakeTorque = 0f;
            }
            else
            {
                FR_Collider.motorTorque = 0f;
                FL_Collider.motorTorque = 0f;

                FR_Collider.brakeTorque = BrakeForce;
                FL_Collider.brakeTorque = BrakeForce;
                BR_Collider.brakeTorque = BrakeForce;
                BL_Collider.brakeTorque = BrakeForce;
            }
        }
        else
        {
            FR_Collider.motorTorque = 0f;
            FL_Collider.motorTorque = 0f;

            FR_Collider.brakeTorque = BrakeForce;
            FL_Collider.brakeTorque = BrakeForce;
            BR_Collider.brakeTorque = BrakeForce;
            BL_Collider.brakeTorque = BrakeForce;
        }
    }
示例#12
0
    IEnumerator RandomCalls()
    {
        while (true)
        {
            yield return(new WaitForSeconds(Random.Range(PhoneCallRandomness.x, PhoneCallRandomness.y)));

            int     RandomCaller = Random.Range(0, SpamCallers.Count);
            TextBox TB           = null;
            while (!TB)
            {
                yield return(new WaitForSeconds(0.5f));

                TB = GameObject.FindWithTag("TextBox").GetComponent <TextBox>();
            }

            if (!GetComponent <DashObject>().PickedUp&& !GetComponent <DashObject>().Locked&& !InCall && !TB.isActive)
            {
                if (GameObject.FindWithTag("Manager").GetComponent <Manager>().TimeIndex != 0 && GameObject.FindWithTag("Manager").GetComponent <Manager>().TimeIndex < 600)
                {
                    ASC.Sound = PhoneCallSound;
                    ASC.SetVolume(1f);
                    ASC.AS.loop = true;
                    ASC.Play();

                    PhoneNumber      = "";
                    PhoneScreen.text = "Incoming : " + SpamCallers[RandomCaller].CallerID;
                    DashObject DO = GetComponent <DashObject>();

                    int  Frames   = 0;
                    bool Answered = false;
                    while (Frames < (7 * 60))
                    {
                        yield return(null);

                        Frames++;

                        if (DO.PickedUp)
                        {
                            Answered = true;
                            Frames   = 1000;
                        }
                    }

                    if (Answered)
                    {
                        PhoneScreen.text = SpamCallers[RandomCaller].CallerID;
                        InCall           = true;

                        ASC.AS.loop = false;
                        ASC.Stop();


                        TB.CurrentVoice  = SpamCallers[RandomCaller].CallerVoice;
                        TB.CurrentSource = ASC;
                        ASC.SetVolume(1f);

                        int Index = 0;

                        bool HungUp = false;

                        while (Index < SpamCallers[RandomCaller].Lines.Count && HungUp == false)
                        {
                            TB.DisplayText(SpamCallers[RandomCaller].Lines[Index]);

                            while (TB.isPrinting && HungUp == false)
                            {
                                yield return(null);

                                if (!DO.PickedUp)
                                {
                                    HungUp = true;
                                }
                            }

                            /*
                             * Frames = 0;
                             * while(!HungUp && Frames < 30)
                             * {
                             *  yield return null;
                             *  Frames++;
                             *  if(!DO.PickedUp)
                             *  {
                             *      HungUp = true;
                             *  }
                             * }*/

                            Index++;
                        }

                        TB.Toggle();
                        ASC.SetPitch(1f);

                        if (!HungUp)
                        {
                            GetComponent <DashObject>().RemoveFromHands();
                        }

                        Clear();
                        InCall = false;
                    }

                    ASC.AS.loop = false;
                    ASC.Stop();

                    PhoneScreen.text = "";
                }
            }
        }
    }