I am trying to move two independent players using Input.GetTouch in different parts of the screen. The problem is currently only one can be moved at a time. Is there anyway I can split the screen to handle movement of these separately ?
This is the script for one of the players:
using UnityEngine;
using System;
public class LTouchFollow : MonoBehaviour
{
public Rigidbody lRb;
public float sideMax = 5f; //Try screen.width
public float midlimit = 1f;
public float playerSpeed = 20f;
public Rect left = new Rect(0f, 0f, Screen.width/2, Screen.height);
void Start()
{
lRb = GetComponent<Rigidbody>();
}
// Update is called once per frame
public void FixedUpdate()
{
if (Input.touchCount > 0)
{
Touch lTouchPx = Input.GetTouch(0);
if (left.Contains(lTouchPx.position))
{
Debug.Log("FuncionaL");
Vector3 lTouchUnt = Camera.main.ScreenToWorldPoint(lTouchPx.position);
Vector3 lTargetPosition = new Vector3(lTouchUnt.x, 8f, 0f);
lTargetPosition.x = Mathf.Clamp(lTargetPosition.x, -sideMax, -midlimit);
transform.position = Vector3.Lerp(transform.position, lTargetPosition, Time.deltaTime * playerSpeed);
}
}
}
}