【发布时间】:2016-04-13 12:59:09
【问题描述】:
目前,我正在尝试将一个脚本中的值添加/减去另一个脚本。我希望脚本一为脚本二添加 +125 生命值,但不知道如何。此场景中不涉及游戏对象。
脚本一是
using UnityEngine;
using System.Collections;
public class AddHealth : MonoBehaviour {
int health = 10;
public void ChokeAdd()
{
AddHealthNow();
}
public void AddHealthNow()
{
health += 125;
Debug.Log("Added +125 Health");
}
}
脚本二是
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace CompleteProject
{
public class DataManager : MonoBehaviour
{
public static int depth;
public Text BOPPressureText;
int health = 20;
void Awake ()
{
depth = 0 ;
}
void Update ()
{
BOPPressureText.text = depth + 7 * (health) + " psi ";
}
}
}
【问题讨论】:
-
"此场景中不涉及游戏对象。"当您在 Unity 中工作时,这是一个相当大的要求,而且非常重要。在不将它们与游戏对象关联的情况下,您是如何制作这些组件的?