我在团结中执行Healthbar脚本。有用。但是法术力吧脚本没有。我还有一个带有静态变量的脚本,用于健康和法力系统。 我有2张图片,我希望在健康/法力消耗时填充。健康栏有效。但是法力吧不是。没有任何编译错误。只是脚本不起作用。
以下是医疗系统脚本:
using UnityEngine;
using System.Collections;
public class HealthMana : MonoBehaviour {
public static float CurrentHealth;
public float MaximumHealth;
public float RegenSpeed;
public bool CanRegen;
public static float CurrentMana;
public float MaximumMana;
public float RegenManaSpeed;
public bool CanRegenMana;
public void Awake () {
CurrentHealth = 100.0f;
MaximumHealth = 100.0f;
RegenSpeed = 1.0f;
CanRegen = true;
CurrentMana = 10.0f;
MaximumMana = 100.0f;
RegenManaSpeed = 1.0f;
CanRegenMana = true;
}
void Start () {
}
void Update () {
if (CanRegen == true && CurrentHealth <= MaximumHealth){
CurrentHealth = CurrentHealth + RegenSpeed * Time.deltaTime;
}
if (CanRegenMana == true && CurrentMana <= MaximumMana) {
CurrentMana = CurrentMana + RegenManaSpeed * Time.deltaTime;
}
}
}
ManaUI的代码(图2)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ManaUI : MonoBehaviour {
void Update () {
Image image = GetComponent<Image>("Image1");
float fillamount = HealthMana.CurrentMana / 100;
image.fillAmount = fillamount;
}
}
healthUI代码是相同的,但它表示CurrentHealth而不是CurrentMana