Unity中血条ui制作(二)
Unity中血条ui制作(二) 代码 : using UnityEngine ; public class HealthBar : MonoBehaviour { public float healthValue = 100f ; //血量上限 /// <summary> /// 当前血量属性,外部访问器 /// </summary> public float Health { get { return health ; } set { if ( health != value ) { Refresh ( ) ; health = value ; } } } private float health ; private void Start ( ) { health = healthValue ; transform . localScale . Normalize ( ) ; } void Refresh ( ) { transform . localScale = new Vector3 ( Health / healthValue , 1 , 1 ) ; } } 思路 : 根据血量控制血条Bar物体的transform.localScale的x轴值. 脚本要挂在Bar物体上. using UnityEngine ; public class PlayerHealth :