• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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 /
avatar image
0
Question by PsychOXRat · Mar 16, 2015 at 07:42 AM · c#audionullreferenceexceptioncarvehicle

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.

Comment
Add comment · Show 2
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 meat5000 ♦ · Mar 16, 2015 at 12:43 AM 1
Share

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 instead.

avatar image PsychOXRat · Mar 16, 2015 at 08:03 PM 0
Share

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).sqrMagnitude; I have no idea what to do to fix this at all

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 1 · Share
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 spencore · Aug 29, 2018 at 02:15 AM 0
Share

ok well this fixed it for me. im totally new, so i have no idea why - but thanks!

avatar image
0

Answer by LarryPlaysYT · Jan 21 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.

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Distribute terrain in zones 3 Answers

get in get out of a car. Unet 0 Answers

Why does my car re-align after drift into the original direction? 0 Answers

SOLVED- Null Reference Exception related to OnAudioFilterRead 0 Answers

How to make AudioSource play defined clips using String? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges