I’m trying to get my player to follow my mouse and cant seem to get anywhere. Ive tried looking up tutorials but none of them are what I want it to do. All I want is for the player on the screen to see where the mouse is and be at that exact position. Also i’m in C#.
P.S.
I have never coded ever so if you could try to explain how this works that would be pretty neat.
public class MouseMove2D : MonoBehaviour {
private Vector3 mousePosition;
public float moveSpeed = 0.1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(1)) {
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
}
}