River Jiang
2020-10-22 01fe52bc3f5df9924b26426c27a4277f4848f071
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;
using UnityEngine.UI;
 
namespace TowerDefense.UI
{
    /// <summary>
    /// UI object to display final score
    /// </summary>
    public class ScorePanel : MonoBehaviour
    {
        /// <summary>
        /// Objects that represent the stars
        /// </summary>
        public Image[] starImages;
 
        public Sprite achievedStarSprite;
 
        /// <summary>
        /// Show the correct number of stars for the score
        /// </summary>
        /// <param name="score">The final score</param>
        public void SetStars(int score)
        {
            if (score <= 0)
            {
                return;
            }
            score = Mathf.Clamp(score, 0, starImages.Length);
            for (int i = 0; i < score; i++)
            {
                starImages[i].sprite = achievedStarSprite;
            }
        }
    }
}