- Home /
Convert Input Mouse in Input touch and test Unity
Hi guys,
I have problem in convert Input Mouse to Input Touch before testing on Unity. My code to the gameObject Plataforma to move with mouse in axis x right and left:
using UnityEngine; using System.Collections;
public class Plataforma : MonoBehaviour {
public float velocidadeDeMovimento;
public float limiteEmX;
// Use this for initialization
void Start ()
{
limiteEmX = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x - GetComponent<SpriteRenderer>().bounds.extents.x;
}
// Update is called once per frame
void Update ()
{
float direçãoHorizontalDoMouse = Input.GetAxis ("Mouse X"); // -1 = esquerdo; 0 = parado; 1 = direita
GetComponent<Transform>().position += Vector3.right * direçãoHorizontalDoMouse * velocidadeDeMovimento * Time.deltaTime;
float xAtual = transform.position.x;
xAtual = Mathf.Clamp (xAtual, -limiteEmX, limiteEmX);
transform.position = new Vector3 (xAtual, transform.position.y, transform.position.z);
}
}
I need to do the gameObject Plataforma respond in touch, but when touch with finger on the Plataforma it need to move to right and left axis X only. And still, I need to test the preview in Unity, to know How will the game to respond on mobile. Sorry my English.
I thank the attention!!!
Regards,
Maicon.
Your answer
Follow this Question
Related Questions
Why does my sound play multiple times using touchcount? 1 Answer
How can I implement iOS TouchScreenKeyboard 'Next' and 'Go' keys? 0 Answers
How to implement android touch input joysticks for the lego microgame 2 Answers
check touch position 2 Answers
How to enable multiple button presses on a touchscreen virtual button control scheme 1 Answer