【发布时间】:2016-09-23 19:00:05
【问题描述】:
我有一个名为 Death 的脚本,当碰撞为真时,它会在起始位置重新生成玩家。我正在尝试计算分数,当这种碰撞为真时,它将减去 100 分,但没有成功。下面的脚本如果来自得分和死亡脚本。任何帮助将不胜感激。
评分脚本:
var gui : GameObject;
static var score : int;
Death.death = false;
function Start ()
{
gui.GetComponent ("GUIText").text = "Score: 0";
}
function Update ()
{
gui.GetComponent ("GUIText").text = "Score: " + score;
if (death)
{
score = score - 100;
}
}
死亡脚本:
#pragma strict
var Ball : Transform;
public var death : boolean = false;
function OnCollisionEnter (b : Collision)
{
if (b.gameObject.tag == "Ball")
{
death = true;
Ball.transform.position.x = 1.6;
Ball.transform.position.y = 1.5;
Ball.transform.position.z = 1.1;
Ball.GetComponent.<Rigidbody>().velocity.y = 0;
Ball.GetComponent.<Rigidbody>().velocity.x = 0;
Ball.GetComponent.<Rigidbody>().velocity.z = 0;
}
}
【问题讨论】:
-
在update函数中,在设置分数之前把if (death)检查一下。
标签: javascript unity3d scripting