Let’s say I have a value called inkMeter, and I want to decrease it depending on how far user move their mouse when user hold left mouse button.
I’ve tried it but it’s still incorrect. When I move my mouse slowly inkMeter value decrease fast, but if I move it fast inkMeter value decrease slowly. I think it’s affected by FPS and yes, my function is in an update method.
Is there any way to approach this? I’m still clueless.
Thanks!
I’m not 100% certain exactly what behavior you want to achieve, but this script will lower inkMeter by the current distance the mouse has moved since the mouse button was held down.
public float inkMeter;
//The values of inkMeter and the mouse position when the mouse is initially pressed
private float inkMeterStart;
private Vector3 mousePositionStart;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//When the mouse button is first pressed down, save the current values
inkMeterStart = inkMeter;
mousePositionStart = Input.mousePosition;
}
else if (Input.GetMouseButton(0))
{
//Find the distance the mouse has moved from it's starting position
float moveDistance = Vector3.Distance(mousePositionStart, Input.mousePosition);
//Decrease inkMeter by the distance the mouse has moved
inkMeter = inkMeterStart - moveDistance;
}
}