Question

I'm trying to do a porting from a platform game made for PC to Android and right now I'm stuck in this part : The inputs

So basicly, I reviewed all the Unity documentations and forums but not a lot of them talk about. Here is the portion of code

function UpdateSmoothedMovementDirection () {   
var h = Input.GetAxisRaw ("Horizontal");

I read that Android and iOs are not compatible with the Input Manager. For now, I placed a joystick (the prefab one from Unity) and I want to get the Axis but I can't figure how to do so !

Was it helpful?

Solution

I was in the same boat as you not too long ago.

private var joystickObj : GameObject;
private var joystick : Joystick;

function Start () {
    joystickObj = GameObject.Find("Single Joystick");
    joystick = joystickObj.GetComponent(Joystick);
}


function Update () {
    if (joystick.position.x > .5) {
        //do stuff  
    }
    else if (joystick.position.x < -.5) {
        //do other stuff
    }
}

You can use joystick.position.y if you want to use that too.

OTHER TIPS

Your function "UpdateSmoothedMovementDirection" should be called on each frame under the Update() function.

function Update () {
        var speed : float = Input.GetAxisRaw("Horizontal") * Time.deltaTime;
        transform.Rotate (0, speed, 0); 
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top