I have a 3d block slide game, where you have to bypass obstacles to get to the finish line.(pretty basic) You press A and it goe's left, you press D and it goes's right. I want to make the game for android phone too so i right some code to implement these: when i press anywhere on the left side on the screen to go left like you would press a button and the same with the right part. (i am not too good at righting code) and it works very strange, not as it should do.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchControls : MonoBehaviour {
public float moveSpeed;
private object mousePos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void FixedUpdate()
{
TouchMove();
}
void TouchMove()
{
if(Input.GetMouseButton(0))
{
Vector3 mosuePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (mosuePos.x > 1)
{
transform.Translate(moveSpeed, 0, 0);
}
else if (mosuePos.x < -1)
{
transform.Translate(-moveSpeed, 0, 0);
}
}
}
}