So i am currently working on a mobile game and i am making a hyper casual game.
i have wrote the code perfectly but i am not getting desired output of moving player right and left. so can anyone tell where i have gone wrong. the code is provided below…
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private Transform playerTransform;
[SerializeField] private float limitValue;
private void update()
{
if(Input.GetMouseButton(0))
{
MovePlayer();
}
}
private void MovePlayer()
{
//calculate x position and move it there...
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, 0, 0);
}
}
Please if anyone know the alternative of the function plz reply
thanks ,So i was making a hyper casual game i wrote the code perfectly yet i am not getting desired output to move the character left and write. its a mobile game.
The code is given below
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private Transform playerTransform;
[SerializeField] private float limitValue;
private void update()
{
if(Input.GetMouseButton(0))
{
MovePlayer();
}
}
private void MovePlayer()
{
//calculate x position and move it there...
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, 0, 0);
}
}