【发布时间】:2016-01-02 06:57:32
【问题描述】:
这是玩家健康脚本...它在 Unity 中设置玩家健康,并将其推送到 GUI。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour
{
public Text hpText; //HP Value Text Element.
public int PlayerHP; // Make it a property so you can alter its value in the editor
void Start()
{
SetHPText ();
}
void Update ()
{
SetHPText ();
}
void SetHPText ()
{
hpText.text = "Health: " + PlayerHP.ToString();
}
}
然后这个获取玩家当前的健康状况(并保持更新)。如果玩家的生命值为 0(或更低),它会加载一个新场景。问题是玩家的标签标签检查,并且应用伤害不起作用。
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class DamageAuroa : MonoBehaviour {
public int PHP; //PHP = Player Health from PlayerHealth.cs script.
public int Damage; //Amount of damage.
public string Level;
void Update()
{
PHP = GameObject.Find("Player").GetComponent<PlayerHealth>().PlayerHP;
}
void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.tag == "Player")
PHP = PHP - Damage;
if (coll.gameObject.tag == "Ball")
{
gameObject.SetActive(false);
SceneManager.LoadScene(Level);
}
if (PHP <= 0)
SceneManager.LoadScene(Level);
}
}
在我更新 Unity 之前,所有这一切都是最奇怪的部分(我知道新手的错误)。有谁看到是怎么回事?在任何人问是之前,触发器和标签都已正确设置。另外我意识到我必须将更新后的 HP 值传递给玩家健康脚本,以便它在 GUI 上更新。只是试图让这些触发器发挥作用。
【问题讨论】: