How to get a meter working,How to fix my meter for my game
I'm trying to make a game where you use your soul to battle enemies, and I'm trying to make a meter to show the player how much soul they have left. Whenever I try to make it any value, it goes to half and when I try to set it back to the max value, it stays at half. This is the code that is giving me the issue: if(Humanity < oldHumanity) { currentPosition = oldCurrentPosition - 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; } if(Humanity > oldHumanity) { currentPosition = oldCurrentPosition + 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; } if(Humanity > 50) { Humanity = 50; } The variables it is calling are right here: public int Humanity = 50; private int currentPosition = -2; private int oldHumanity = 50; private int oldCurrentPosition = -2; ,Ok I am making a game where you use your soul to fight enemies. I'm trying to make a meter to show the player what their soul amount is at, but for some reason when I try to set it to any value it just goes to half, and it won't go any higher even if I set it back to it's max value. This is what my code looks like: if(Humanity < oldHumanity) { currentPosition = oldCurrentPosition - 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; } if(Humanity > oldHumanity) { currentPosition = oldCurrentPosition + 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; The variables that it's calling are right here: public int Humanity = 50; private int currentPosition = -2; private int oldHumanity = 50; private int oldCurrentPosition = -2;
For some reason its not sorting my code from my normal text even though I hit the code sample button I'll try again. if(Humanity < oldHumanity) { currentPosition = oldCurrentPosition - 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; } if(Humanity > oldHumanity) { currentPosition = oldCurrentPosition + 1; oldCurrentPosition = currentPosition; transform.position = new Vector3(-2, currentPosition, -1); oldHumanity = Humanity; } if(Humanity > 50) { Humanity = 50; } And here are the variables: public int Humanity = 50; private int currentPosition = -2; private int oldHumanity = 50; private int oldCurrentPosition = -2;
Your answer
![](https://koobas.hobune.stream/wayback/20220613005340im_/https://answers.unity.com/themes/thub/images/avi.jpg)