Hello,
I am VERY new to code and have hardly written more than an HTML web page.
I am getting the following error in my CONSOLE:
[10142-screen+shot+2013-04-16+at+6.07.28+pm.png|10142]
I understand what ever i need is making my forward arrow not work (driving a motorcycle in the game) and that it needs to UPDATE every frame to make sure your still holding down that forward key. Problem is i have NO idea how to reference or fix this. SO new to coding you will have to explain to me exactly what to do! Thanks!
Here are the pictures of the code around the LINE that it is referencing as having a problem.
[10143-code+pic.jpg|10143]
Thanks for the Help!
I Just need to know what line I’m missing that it cant find and how to write it, I can tell you what you need to know like name of game objects, scripts, and or components.
3 Answers
3
For the error on line 104, there are 2 possibility:
-
GetComponent.< SmoothFollow >() returns a null
-
body is a null, so body.transform throws a null-ref exception In line 117, you use body.GetComponent() and it has no problem, so the body is not null Not exactly sure about this one. Need a Debug.Log( body != null ) to find out.
For the error on line 286:
-
audioSource is null
In order to prevent null references you should always protect code that works with possibly unassigned references with a conditional; ‘if the thing I’m looking for is present, then do something with it’. In code, that looks like this:
if (thingImLookingFor != null)
{
// do something with thingImLookingFor
}
In your particular case, you probably want to try the following:
SmoothFollow smoothFollow = Camera.mainCamera.GetComponent.< SmoothFollow >();
if (smoothFollow != null)
{
smoothFollow.target = body.transform;
}
These are all true BUT I did the simple thing as to LINK the incorrect script :P. Yes im that new to unity :P. WHat it was is there was too smooth follow scripts. One was in the folder that another script was looking for and what was in a folder that was obsolete I chose the one that was obsolete and so it threw a null :P. All I did was link proper script that was in the folder that the other script was looking for and it instantly worked. 
Thank you so much for your time and I’m sorry that it was something so simple and stupid! But I learned something from you guys so this is good!
Please reply using the coding field option :P it will save a bit of time!
– Daniel_GPlease post code in future instead of an image. Then people can test it without having to write the whole thing out .... http://answers.unity3d.com/page/newuser.html
– AlucardJay