|
I am adding to the Car Tutorial a particle system that is using the following script. If you take note the script is actually modified from the Pickup script from the 3D Platform Game. I want it so that when the car collides with the particle system, the top speed is increased. This script is added to the particle system. When I run the program, I am getting an error: NullReferenceException: Object reference not set to an instance of an object UpdateTopSpeed.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Scripts/JavaScripts/UpdateTopSpeed.js:41) Does anyone know how to fix this error or how to change the code around so that I don't have to worry about the error. Note I have not changed much from the tutorial besides adding the particle system and creating this script called UpdateSpeed. Thank you!
(comments are locked)
|
|
If Car is a script and UpdateSpeed() a function of it, you could use this:
...
var carStatus : Car = col.GetComponent(Car);
carStatus.UpdateSpeed();
...
or just this:
...
col.GetComponent(Car).UpdateSpeed();
...
This didn't work. I am still getting the same error.
May 07 '12 at 12:18 AM
unityquestions12345
ALDO DO MY QUESTION ON THE UNANSWERED QUESTION PAGES! He doesnt have it as it... Maybe you should try another script. Perhaps make your own?
May 07 '12 at 12:27 AM
maroonrs2
Probably GetComponent have not found the script Car in the object that entered the trigger, or the function UpdateSpeed doesn't exist/is misspelled. The object may not be the car, or the script Car isn't attached to it. You should use some print instructions to help finding the cause:
...
if(mover && mover.enabled) return;
var carStatus : Car = col.GetComponent(Car);
if (carStatus){
carStatus.UpdateSpeed();
} else {
print("Script Car not found in "+col.name);
}
...
If the object detected doesn't have the script Car, this will print a warning and the name of this object.
May 07 '12 at 02:15 PM
aldonaletto
(comments are locked)
|

I have established that the error is within these two lines:
var carStatus : Car = col.GetComponent(Car); carStatus.GetComponent(Car).UpdateSpeed();
Wait it's not a variable yet... You need to make it a variable b4 anything. Null means nothing. Referance means it cannot refer to something, error means failure to do... umm and the object must be a trigger/ have trigger flagged/ have trigger thing checked ont he collider.