Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LovelyVibes · Aug 03, 2017 at 08:24 AM · c#

Why am I getting a Null Reference Exception?

I am receiving a null reference exception error and I am not quite sure why, with the way the code is structured I would think that the script would find my wheel collider's however even after attaching them by hand it then gives an out of range error.

Here is the code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class BasicVehControls : MonoBehaviour
 {
 
     public int bhp;
     public float torque;
     public int brakeTorque;
 
     public float[] gearRatio;
     public int currentGear;
 
     public WheelCollider FL;
     public WheelCollider FR;
     public WheelCollider RL;
     public WheelCollider RR;
 
     public float currentSpeed;
     public int maxSpeed;
     public int maxRevSpeed;
 
     public float SteerAngle;
 
     public float engineRPM;
     public float gearUpRPM;
     public float gearDownRPM;
     private GameObject COM;
 
     public bool handBraked;
 
     public List<AudioSource> CarSound;
 
     public float[] MinRpmTable = {50.0f, 75.0f, 112.0f, 166.9f, 222.4f, 278.3f, 333.5f, 388.2f, 435.5f, 483.3f, 538.4f, 594.3f, 643.6f, 692.8f, 741.9f, 790.0f};
     public float[] NormalRpmTable = {72.0f, 93.0f, 155.9f, 202.8f, 267.0f, 314.5f, 377.4f, 423.9f, 472.1f, 519.4f, 582.3f, 631.3f, 680.8f, 729.4f, 778.8f, 826.1f};
     public float[] MaxRpmTable = {92.0f, 136.0f, 182.9f, 247.4f, 294.3f, 357.5f, 403.6f, 452.5f, 499.3f, 562.5f, 612.3f, 661.6f, 708.8f, 758.9f, 806.0f, 1000.0f};
     public float[] PitchingTable = {0.12f, 0.12f, 0.12f, 0.12f, 0.11f, 0.10f, 0.09f, 0.08f, 0.06f, 0.06f, 0.06f, 0.06f, 0.06f, 0.06f, 0.06f, 0.06f};
     public float RangeDivider = 4f;
     public float soundRPM;
 
     void Start()
     {
 
         FL = GameObject.Find("FL.Col").GetComponent<WheelCollider>();
         Debug.Log("Front Left Wheel Collider Found.");
         FR = GameObject.Find("FR.Col").GetComponent<WheelCollider>();
         Debug.Log("Front Right Wheel Collider Found.");
         RL = GameObject.Find("RL.Col").GetComponent<WheelCollider>();
         Debug.Log("Rear Left Wheel Collider Found.");
         RR = GameObject.Find("RR.Col").GetComponent<WheelCollider>();
         Debug.Log("Rear Right Wheel Collider Found.");
 
         COM = GameObject.Find("Col");
         GetComponent<Rigidbody>().centerOfMass = new Vector3(COM.transform.localPosition.x * transform.localScale.x, COM.transform.localPosition.y * transform.localScale.y, COM.transform.localPosition.z * transform.localScale.z);                    
 
         for(int i =1; i<=16; ++i) 
         {
             //CarSound.Add(GameObject.Find(string.Format("CarSound ({0})",i)).GetComponent<AudioSource>());
             //CarSound[i-1].Play();
         }
 
     }
     
 
     void Update()
     {
         //Functions to access.
         Steer();
         AutoGears();
         Accelerate();
         carSounds ();
 
         //Defenitions.
         currentSpeed = GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
         engineRPM = Mathf.Round((RL.rpm * gearRatio[currentGear]));
         soundRPM = Mathf.Round(engineRPM * (1000 / 420));
         torque = bhp * gearRatio[currentGear];     
 
         if (Input.GetButton("Jump"))
         {
             HandBrakes();
         }
         
         if (Input.GetKey(KeyCode.R)) {
 
             transform.position.Set(transform.position.x, transform.position.y + 5f, transform.position.z);
             transform.rotation.Set(0,0,0,0);
         }
     }
 
 
     //Function
 
     void Accelerate()
     {
 
         if (currentSpeed < maxSpeed && currentSpeed > maxRevSpeed && engineRPM <= gearUpRPM)
         {
 
             RL.motorTorque = torque * Input.GetAxis("Vertical");
             RR.motorTorque = torque * Input.GetAxis("Vertical");
             RL.brakeTorque = 0;
             RR.brakeTorque = 0;
         }
         else
         {
 
             RL.motorTorque = 0;
             RR.motorTorque = 0;
             RL.brakeTorque = brakeTorque;
             RR.brakeTorque = brakeTorque;
         }
 
         if (engineRPM > 0 && Input.GetAxis("Vertical") < 0 && engineRPM <= gearUpRPM)
         {
             
             FL.brakeTorque = brakeTorque;
             FR.brakeTorque = brakeTorque;
         }
         else
         {
             FL.brakeTorque = 0;
             FR.brakeTorque = 0;
         }
     }
 
     void Steer()
     {
 
         if (currentSpeed < 100)
         {
             SteerAngle = 13 - (currentSpeed / 10);
         }
         else
         {
             SteerAngle = 2;
         }
 
         FL.steerAngle = SteerAngle * Input.GetAxis("Horizontal");
         FR.steerAngle = SteerAngle * Input.GetAxis("Horizontal");
     }
 
 
     void AutoGears()
     {
 
         int AppropriateGear = currentGear;
 
         if (engineRPM >= gearUpRPM)
         {
 
             for (var i = 0; i < gearRatio.Length; i++)
             {
                 if (RL.rpm * gearRatio[i] < gearUpRPM)
                 {
                     AppropriateGear = i;
                     break;
                 }
             }
             currentGear = AppropriateGear;
         }
 
         if (engineRPM <= gearDownRPM)
         {
             AppropriateGear = currentGear;
             for (var j = gearRatio.Length - 1; j >= 0; j--)
             {
                 if (RL.rpm * gearRatio[j] > gearDownRPM)
                 {
                     AppropriateGear = j;
                     break;
                 }
             }
             currentGear = AppropriateGear;
         }
     }
 
     void HandBrakes()
     {
 
         RL.brakeTorque = brakeTorque;
         RR.brakeTorque = brakeTorque;
         FL.brakeTorque = brakeTorque;
         FR.brakeTorque = brakeTorque;
     }
 
     void carSounds()
     {
 
         for (int i = 0; i < 16; i++) {
             if (i == 0) {
                 //Set CarSound[0]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[0].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[0].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[0].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[0].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[0].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[0].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[0].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 1) {
                 //Set CarSound[1]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[1].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[1].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[1].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[1].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[1].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[1].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[1].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 2) {
                 //Set CarSound[2]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[2].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[2].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[2].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[2].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[2].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[2].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[2].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 3) {
                 //Set CarSound[3]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[3].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[3].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[3].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[3].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[3].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[3].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[3].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 4) {
                 //Set CarSound[4]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[4].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[4].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[4].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[4].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[4].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[4].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[4].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 5) {
                 //Set CarSound[5]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[5].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[5].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[5].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[5].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[5].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[5].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[5].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 6) {
                 //Set CarSound[6]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[6].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[6].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[6].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[6].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[6].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[6].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[6].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 7) {
                 //Set CarSound[7]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[7].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[7].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[7].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[7].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[7].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[7].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[7].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 8) {
                 //Set CarSound[8]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[8].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[8].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[8].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[8].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[8].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[8].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[8].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 9) {
                 //Set CarSound[9]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[9].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[9].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[9].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[9].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[9].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[9].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[9].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 10) {
                 //Set CarSound[10]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[10].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[10].volume = ((ReducedRPM / Range) * 2f) - 1f;
                     //CarSound[10].volume = 0.0f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[10].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[10].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[10].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[10].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[10].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 11) {
                 //Set CarSound[11]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[11].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[11].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[11].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[11].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[11].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[11].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[11].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 12) {
                 //Set CarSound[12]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[12].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[12].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[12].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[12].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[12].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[12].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[12].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 13) {
                 //Set CarSound[13]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[13].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[13].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[13].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[13].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[13].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[13].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[13].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 14) {
                 //Set CarSound[14]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[14].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[14].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[14].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[14].volume = 1f;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[14].pitch = 1f + PitchMath;
                 } else if (soundRPM > MaxRpmTable[i]) {
                     float Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider;
                     float ReducedRPM = soundRPM - MaxRpmTable[i];
                     CarSound[14].volume = 1f - ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     //CarSound[14].pitch = 1f + PitchingTable[i] + PitchMath;
                 }
             } else if (i == 15) {
                 //Set CarSound[15]
                 if (soundRPM < MinRpmTable[i]) {
                     CarSound[15].volume = 0.0f;
                 } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) {
                     float Range = NormalRpmTable[i] - MinRpmTable[i];
                     float ReducedRPM = soundRPM - MinRpmTable[i];
                     CarSound[15].volume = ReducedRPM / Range;
                     float PitchMath = (ReducedRPM * PitchingTable[i]) / Range;
                     CarSound[15].pitch = 1f - PitchingTable[i] + PitchMath;
                 } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) {
                     float Range = MaxRpmTable[i] - NormalRpmTable[i];
                     float ReducedRPM = soundRPM - NormalRpmTable[i];
                     CarSound[15].volume = 1f;
                     float PitchMath = (ReducedRPM * (PitchingTable[i] + 0.1f)) / Range;
                     CarSound[15].pitch = 1f + PitchMath;
                 }
             }
         }
     }
     }


And here is the error log

NullReferenceException: Object reference not set to an instance of an object BasicVehControls.Start () (at Assets/BasicVehControls.cs:45)

If you need any additional information just ask and I will do my best to provide it, I am very new to C# so any help at all even just a nudge in the right direction would be very much appreciated, thank you.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadoX · Aug 03, 2017 at 08:24 AM 0
Share

That's a lot of code :D ( not sure if we need all of it for this hah )

If I get it correctly, you're getting the NullPointerException on this line:

 FL = GameObject.Find("FL.Col").GetComponent<WheelCollider>();

So my guess would be that it can't find a GameObject named "FL.Col" so try making sure that at the time of this lines execution, there is a GameObject called "FL.Col" in the Scene.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

401 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Free Look Camera Rig Changing Rotation 1 Answer

Rotating an Object Around a Point? C# 0 Answers

Need help with coding 0 Answers

[Help][Noob] My Enums/Input won't work 1 Answer

Does anyone have a good script that can be used to make a horse/vehicle rideable? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges