unity中怎么用JS修改其他脚本的变量

2024-11-02 08:19:53
推荐回答(1个)
回答1:

var HP : PLAYERHP;
function Start () {
HP = GameObject.Find("PLAYER-HP").GetComponent(PLAYERHP);
}
function Update () {
}
function OnParticleCollision (other : GameObject) {
if (other.gameObject.tag == "WALL-ATTACK")
{
HP.Health = HP.Health - 5;
//此脚本侦测到粒子碰撞时PLAYERHP里的Health变量减5~~
print(HP.Health);
//显示PLAYERHP里的Health变量~~
}
}