123456789101112131415161718192021222324252627282930 |
- using System.Collections;
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- public class ProgressBar : MonoBehaviour
- {
- // Start is called before the first frame update
- public Image progressBarBody;
- public Image progressBarBackground;
- public int setValue=0;
- private float step;
- private float height;
- void Start()
- {
- step = progressBarBody.GetComponent<RectTransform>().rect.width / 100;
- height = progressBarBody.GetComponent<RectTransform>().rect.height;
-
- }
- // Update is called once per frame
- void Update()
- {
- float width = step * setValue;
- progressBarBody.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
- progressBarBody.GetComponent<RectTransform>().anchoredPosition = new Vector2(width/2,0);
- }
- }
|