- Home /
Question by
teixeira · Feb 22, 2014 at 04:02 AM ·
gameobjectjoystickkeyboardmovepositiongamecontroller
keyboard commands to Joystik C# "Object reference not set to an instance of an object"
Hello, I would like to change keyboard commands to Joystik. Unity returns the error "Object reference not set to an instance of an object"
public class Inputer {
public bool handbreak;
public float vertical;
public float horizontal;
Joystick moveJoystick;
Joystick rotateJoystick;
public void SetInput() {
//handbreak = Input.GetButton("Jump");
vertical = moveJoystick.position.x;//Input.GetAxis("Vertical");
horizontal = moveJoystick.position.y;//Input.GetAxis("horizontal ");
}
}
Comment
Answer by mattyman174 · Feb 22, 2014 at 04:13 AM
Joystick moveJoystick;
Joystick rotateJoystick;
Neither of these variables are Initialised. So when you try and access them the compiler cant find the object your trying to reference.
Your answer
![](https://koobas.hobune.stream/wayback/20220613134319im_/https://answers.unity.com/themes/thub/images/avi.jpg)