- Home /
NullReferenceException: Object reference not set to an instance of an object
hi i get this error at the "if gas HitTest..." part of my code. Do i have to initialize something or maybe create an instance? Any help would be appreciated.
NullReferenceException: Object reference not set to an instance of an object CarMain.SendInput (.CarControl Car, Boolean reverseRequiresStop, Boolean brakeRelease) (at Assets/EdyVehiclePhysics/CarMain.js:383) CarMain.Update () (at Assets/EdyVehiclePhysics/CarMain.js:85)
static function SendInput(Car : CarControl, reverseRequiresStop : boolean, brakeRelease : boolean) : boolean
{
for (var touch : Touch in Input.touches)
{
if (gas.HitTest(touch.position)) // Replace GasButton with your button name
{
Debug.Log("GO");
}
else if (brake.HitTest(touch.position))
{
Debug.Log("STOP");
}
if (left.HitTest(touch.position))
{
Debug.Log("LEFT");
}
else if (right.HitTest(touch.position))
{
Debug.Log("RIGHT");
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135453im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Pause menu error NullReferenceException:Object reference not set to an instance of an Object .js 1 Answer
NullReference Exception when adding a class 2 Answers
The infamous: Object Reference not set to an instance of an object 1 Answer
Instance of an Object not Found 1 Answer
" NullReferenceException: Object reference not set to an instance of an object" 3 Answers