我正在尝试为我的Arcade太空射击游戏创建一个Highscore表,我正在使用变量执行此表,因此不需要DB来存储它们将是临时的分数
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 btw并且我试图访问包含播放器当前得分的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 ();
}
如果有人能完成这个特殊的部分,我会非常感激脚本。
答案 0 :(得分:0)
尝试
scorepoints = Camera.main.GetComponentInChildren("Scorescript");