1.创建Image控件,修改名称为UIProgressBar,创建Image控件,作为血条
2.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test3_1 : MonoBehaviour {
public int Percentage = 100;
Image m_Progress;
Image m_Bar;
float m_proWidth;
float m_barWidth;
float m_barHeight;
float m_maxBarWidth;
// Use this for initialization
void Start () {
GameObject obj = this.gameObject;
m_Progress = obj.GetComponent<Image>();
m_Bar = obj.transform.Find("Bar").GetComponent<Image>();
m_proWidth = m_Progress.rectTransform.rect.width;
m_barWidth = m_Bar.game