Unity Joystick method C#

Flotolk picture Flotolk · Jul 29, 2013 · Viewed 8.1k times · Source

I'm using Unity, and am trying to use the Joystick namespace. but whenever I try to declare a joystic it says the namespace isn't valid.

Here are the libraries I am using:

    using UnityEngine;
    using System.Collections;
    using Riverscout;

And this is the code that gives me the error:

    public Joystick moveJoystick;

Can anyone tell me what library I need to use to make this work? Thanks in advance.

Answer

rutter picture rutter · Jul 30, 2013

The UnityEngine namespace doesn't contain any class named Joystick.

You can, however, access joystick input that has been set up in the Input Manager by querying Input.GetAxis().

Suppose you set up a joystick to control two axes, named "Joy0x" and "Joy0y", you could then get the input like so:

function Update() {
    var x = Input.GetAxis("Joy0x");
    var y = Input.GetAxis("Joy0y");
    transform.Rotate(x, y, 0); //rotate attached GameObject
}

I imagine many people have posted joystick helper scripts. If you're working with one of those, please mention it.