- Home /
How do I make mobile controls work within unity? For example moving, jumping and pressing buttons.
I would like to know how I can make my game have controls for an android device. I watched a video from a you tuber named Jimmy Vegas but unfortunately the buttons in crossPlatformInput remained deactivated in the hierachy. I tried some scripts and it worked for my computer but will it work for mobile devices? Here is the code:
void Update () {
CharacterController controller = GetComponent<CharacterController> ();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0);
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpspeed;
}
moveDirection.x = Input.GetAxisRaw ("Horizontal") * speed;
if(Input.GetMouseButton(0)){
//Are we holding touch on the right side?
if (Input.mousePosition.x > Screen.width / 2) {
moveDirection.x = speed;
}
else
moveDirection.x = -speed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
}
Well, if you have a mobile device then you could test it yourself.
But actually it depends on your input device.
You should be in mobile platform and enable mobile input to enable the mobile cross platform input controls.
Your answer
Follow this Question
Related Questions
Problem in character movement 0 Answers
Android apk lags on all devices except of mine. :/ 0 Answers
Why is my second material not showing up on android 1 Answer
Android App reduce size for PlayStore 1 Answer
Touch Controls for mobile 1 Answer