- Home /
Score sprites not reseting to zero after scene reloads.
Im using number sprites to display the ingame score but when the player scores above 10 or a hundred the sprite stays stuck at the previous score value only the unit value sprite resets back to 0 even though the actual score resets the sprites do not reset.
public class ScoreManagerScript : MonoBehaviour
{
public static int Score { get; set; }
void Awake()
{
(Tens.gameObject as GameObject).SetActive(false);
(Hundreds.gameObject as GameObject).SetActive(false);
}
void Update()
{
if (previousScore != Score)
{
if (Score < 10)
{
Units.sprite = numberSprites[Score];
}
else if (Score >= 10 && Score < 100)
{
(Tens.gameObject as GameObject).SetActive(true);
Tens.sprite = numberSprites[Score / 10];
Units.sprite = numberSprites[Score % 10];
}
else if (Score >= 100)
{
(Hundreds.gameObject as GameObject).SetActive(true);
Hundreds.sprite = numberSprites[Score / 100];
int rest = Score % 100;
Tens.sprite = numberSprites[rest / 10];
Units.sprite = numberSprites[rest % 10];
}
}
}
int previousScore = -1;
public Sprite[] numberSprites;
public SpriteRenderer Units, Tens, Hundreds;
}
Answer by eversunnmustset · Mar 20, 2017 at 01:26 AM
Nvm answered my own question had to move set gameobjects to false in void update.
Your answer
![](https://koobas.hobune.stream/wayback/20220612113507im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How To Sync Scale in UNET 2 Answers
SphereCast doesn't work when I increase the radius. 1 Answer
How to get pixel coordinates when mouse click on Sprite Renderer 0 Answers
How to double spirte/gameobject/prefab and control the result on those items? 0 Answers
How do i change a sprite when another gameobject with the same prefab is colliding / is near 1 Answer