Controlling the Character Controller Using UI?

I have a First Person Controller, and it is currently controlled by W, A, S, D, and Spacebar. I would like to make it so I can have on screen controls (For exporting to Android).

How can I:

  1. Use the controls as buttons?
  2. Code it into the CharacterMotor.js or whatever to use them as inputs instead of W, A, S, D and Spacebar?

22560-fpshelp.jpg

Well you wouldn’t have to alter Character Motor at all. What you do need to do is alter FPSInputController

function Update () {
	// Get the input vector from keyboard or analog stick
	var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

simply put, you need to alter the Vector3 created here by inputing your own values that you get from detecting when a button is pushed or not. for example here’s something you could do:

//this is FPSInputController

private var hMovement:float = 0;
private var vMovement:float = 0;

function Update()
{
    //this is the only change in Update (the first line of update)
    var directionVector = new Vector3(hMovement, 0,vMovement);
}

public function UpdateMovement(var x:float, var y:float)
{
    xMovement = x;
    yMovement = y;
}

Then all you need to do call the UpdateMovement function from your GUI script. You know you could also use Unity’s Mobile Controllers if you wanted to since it’d result in alot less hacked together code.