Ok, So I have a crosshair that gets bigger, as the gun becomes less accurate. I want it to stop at the lowest accuracy (highest value). I first tried an if statement to check if the current accuracy was greater than the lowest accuracy, and then changed the value, but that ended up being jerky. I got the idea to just use clamping, but it is not working and I can’t understand why. The current accuracy’s value just keeps rising past the lowest accuracy.
CODE:
//Update Loop
Mathf.Clamp(currentAccuracy, highestAccuracy, lowestAccuracy);
if (currentAccuracy >= highestAccuracy && firing == false)
{
currentAccuracy -= Time.deltaTime * (speedAccuracyIncrease);
}
if(Input.GetButtonDown("Fire1") && autoFire == false || Input.GetButton("Fire1") && autoFire == true)
{
if(fireDelay <= 0 && ammoClip > 0)
{
firing = true;
if (bullet)
{
currentAccuracy += accuracyDecrease;
}
else
{
firing = false;
}
P.S
lowestAccuracy has the highest value because it is the least accurate and has the most effect on the raycast’s rotation. Same goes for highestAccuracy.
Also, sorry for the weirdly typed code, I removed a lot of it in the editor so you only see what is important and I kind of screwed it up.
– dendens2