- Home /
Car Audio c# script not working
Hi, I've started using Unity 5 for my game, and I needed to use the CarAudio script, however, the script isn't working as it can't find the camera and gives the "NullReferenceException: Object reference not set to an instance of an object" error on line 90 of it, I've done a large amount of searching on this and still haven't found an answer.
As a last resort you can put a
var myCamera : Camera;
in the globals and drag and drop a camera to the script after clicking the gameobject and use that variable ins$$anonymous$$d.
I may have slightly derped whilst writing this, as the line the error points to is line 90, but the error in the console is irrelevant to it in the script, "NullReferenceException: Object reference not set to an instance of an object UnityStandardAssets.Vehicles.Car.CarAudio.Update () (at Assets/Standard Assets/Vehicles/Car/Scripts/CarAudio.cs:90)" Is what the error message, but the line it points to is this: float camDist = (Camera.main.transform.position - transform.position).sqr$$anonymous$$agnitude; I have no idea what to do to fix this at all
Answer by PsychOXRat · Mar 16, 2015 at 08:15 PM
Ok, I fixed it, it was me who was a massive derp and didn't tag the camera as MainCamera :P
ok well this fixed it for me. im totally new, so i have no idea why - but thanks!
Answer by LarryPlaysYT · Jan 21, 2019 at 02:32 AM
Can you paste me the the car audio script because I just started out like a day ago.,Can you send to script because I'm just starting out and I DO NOT know you guys are talking about.