I have tried storing it like : Vector3 firstMousePos = Input.mousePosition
but the variable stores the last mouse pos if I’m moving the mouse…
Here’s a simple example running on Update for the sake of ease:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MousePositionOnClick : MonoBehaviour
{
// The current position of the mouse in pixel coordinates
public Vector3 firstMousePos;
//Whether or not the mouse has been clicked
private bool mouseClicked;
// Update is called once per frame
void Update ()
{
// If left click is pressed & we have not already clicked the button previously
if (Input.GetMouseButtonDown(0) && mouseClicked == false)
{
mouseClicked = true;
firstMousePos = Input.mousePosition;
}
}
}
By using a bool mouseClicked we can stop the mouse position from being updated if the mouse is clicked again.
Keep in mind this will only ever work ONCE unless that same bool is set to false some other way.