Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
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 ins$$anonymous$$d.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
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 3 · 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 Mani2233 · Feb 15, 2020 at 09:40 PM 0
Share

Can you write the code which you change

avatar image AkhilB · Jan 27, 2021 at 12:33 PM 0
Share

Thank you so much, my friend, really thanks a lot.

avatar image
0

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.

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
avatar image
0

Answer by master_rigel · Jun 07, 2019 at 11:13 AM

Thanks PsychOXRat. That fix worked for me too.

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

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

Car engine sound 1 Answer

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

How to play an audio file after another finishes 7 Answers

Multiple Cars not working 1 Answer


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