Joystick typecast returns null

Can you not typecast a GameObject as a Joystick? In my case I have LeftJoystick and RightJoystick GameObjects but if I attempt:

var moveJoystick : Joystick;
moveJoystick = GameObject.Find("LeftJoystick") as Joystick;

In the above example, moveJoystick returns null. It isn’t an issue with Unity not finding “LeftJoystick” as without the typecasting it finds the GameObject.

I am currently using Unity 3.0b7 iPhone. Any ideas?

What is ‘Joystick’? If it’s a script (or class deriving from MonoBehavior) you need to call GetComponent() on the returned GameObject to get a reference to the script attached to it.

If Joystick is something else… then no, you can’t typecast a GameObject to some random other type, no matter what name you give to the game object :stuck_out_tongue:

Dohoy. You are completely right. I was so taken by the new version 3.0 features that I wasn’t seeing very clearly. Simply using GetComponent() fixed everything. Now I have a perfectly working set of joysticks.

Thanks,
Lodlock