Hello everyone. I have a swivel movement for my character and some UI elements on my screen (settings etc.). However when I try to click on those buttons my character also jumps to that side of the screen. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHorizontalMovement : MonoBehaviour
{
[SerializeField] private Transform playerTransform;
[SerializeField] private float limitValue;
void Update()
{
if (Input.GetMouseButton(0))
{
MovePlayer();
}
}
private void MovePlayer()
{
float halfScreen = Screen.width / 2;
float xPos = (Input.mousePosition.x - halfScreen) / halfScreen;
float finalXPos = Mathf.Clamp(xPos * limitValue, -limitValue, limitValue);
playerTransform.localPosition = new Vector3(finalXPos, 1, 0);
}
}
How can I fix this problem?