我正在尝试为我的 Arcade spaceshooter 游戏创建一个 Highscore 表,我用变量做这个表,所以不需要数据库来存储它们将是临时的分数
var high1 : int;
var high2 : int;
var high3 : int;
var high4 : int;
var high5 : int;
function OnGUI () {
var camera;
camera = GameObject.FindWithTag("MainCamera");
var scorepoints;
scorepoints = camera.GetComponent(Scorescript).currentScore;
}
我正在使用 Unity 顺便说一句,我试图访问包含玩家当前分数的 Scorescript,问题是它总是说它找不到脚本的组件,对象标签名称是正确的,脚本名称也是如此,这里是得分脚本:
var customSkin : GUISkin;
var enemy;
enemy = GameObject.FindWithTag("Enemy");
var currentScore : int = 0;
var visibleScore : int = 0;
function OnGUI () {
GUI.skin = customSkin;
GUILayout.BeginArea ( Rect ( Screen.width / 1.2, Screen.height / 10 ,300,200) );
GUILayout.Box ( visibleScore.ToString () );
GUILayout.EndArea ();
}
function AnimateVisibleScore () {
iTween.ValueTo (
gameObject,
{
"from" : visibleScore,
"to" : currentScore,
"onupdate" : "ChangeVisibleScore",
"time" : 0.5
}
);
}
function ChangeVisibleScore ( i : int ) {
visibleScore = i;
}
function IncrementScore ( i : int ) {
currentScore += i;
AnimateVisibleScore ();
}
function DecrementScore ( i : int ) {
currentScore -= i;
AnimateVisibleScore ();
}
如果有人能帮助完成这个特定的部分,我将非常感激。