NullReferenceException when using Single Joystick prefab

Hi everybody

I have the following problem with the Single Joystick prefab (in Standard Assets Mobile)

  • I drop the Single Joystick into my scene
  • Parameters : Dead Zone x = 0, y = 0.5, Normalized = checked

I want to read its x position. So here is what I wrote in my script :

var speedRotation = 3.0;

function Update()


    var joy:Joystick = GetComponent(Joystick);

    transform.Rotate(0, joy.position.x * speedRotation, 0); // this is the line in error in the console


When I launch my game, the console shows me the following error for this line :

NullReferenceException: Object
reference not set to an instance of an

It seems like the “joy” variable is null. So am I doing something wrong ? I tried to put the GetComponent(Joystick) in the Start() function, but same problem.

Thanks in advance

var joy:Joystick = GameObject.Find(“Single Joystick”).GetComponent(Joystick);

did the trick ! Thanks to sysclamoth for inspiring me :slight_smile: