Hello. I make a game on Unity3D 4.6. I made the game, everything is fine on the PC, the control on the keyboard works, but I need to control it on Android, but I just can't. Help me please. Here is my script, the movement is performed by pressing the button (KeyDown) and releasing the button (KeyUp):

void Update(){ if (movePlayer){ //прижок if (grounded && (Input.GetKeyDown (KeyCode.UpArrow))) { //стрибок rigidbody2D.AddForce (new Vector2(0f,jumpForce)); //Включається анімація стрибка anim.SetBool("jump", false); //Координати колайдера boxCollider.size = new Vector2(1.6f, 0.48f); boxCollider.center = new Vector2(-0.08f, -0.71f); } //Приседание if (Input.GetKeyDown (KeyCode.DownArrow)) { //Включається анімація пригинання anim.SetBool("leam", true); //Координати колайдера boxCollider.size = new Vector2(2.0f, 1.5f); boxCollider.center = new Vector2(0.23f, -0.1f); } if (!grounded && (Input.GetKeyUp (KeyCode.UpArrow))) { //Координати колайдера boxCollider.size = new Vector2(0.54f, 2.89f); boxCollider.center = new Vector2(-0.06f, 0.19f); } if (Input.GetKeyUp (KeyCode.DownArrow)) { //Виключається анімація пригинання anim.SetBool("leam", false); //Координати колайдера boxCollider.size = new Vector2(0.54f, 2.89f); boxCollider.center = new Vector2(-0.06f, 0.19f); } //Повернення до початку гри if (Input.GetKey(KeyCode.R)) { Application.LoadLevel(Application.loadedLevel); } } } 
  • 2
    The code demonstrates control from a PC keyboard, ok; But where is the actual attempt to make control on Android? Or is it an Android with a keyboard? - Maxim Kamalov
  • The official manual is not only fully detailed, but even almost completely translated into Russian: docs.unity3d.com/ru/current/Manual/MobileInput.html - Maxim Kamalov
  • one
    assetstore.unity3d.com/en/#!/content/15233 Here is how there is a free solution. However, if I were in your future, I would have thought how to do this if you want to develop in the future ... Think in the direction of Canvas, attach a button there, write an event corresponding to the movement you need ... - user208017

1 answer 1

  1. Create a canvas on the screen
  2. place there any object that responds to click with your finger. (must have "Raycast Target" and it must be set to "true") - for example, Image.
  3. well, on the appropriate raikast event you call the corresponding code block / method.

But this does not help if you need to do svaypy. Swipes are done differently.