【发布时间】:2015-11-19 02:24:01
【问题描述】:
我正在尝试在我的游戏中添加硬币。如果硬币没有被触摸,那么在玩家触摸硬币之前,关卡将无法切换。我的脚本试图在变量中设置一个值,然后当该值增加到 1 时,它允许更改级别。
如何修复我的脚本?
硬币脚本:
using UnityEngine;
using System.Collections;
public class Coin : MonoBehaviour {
public GameObject destroyCoin;
public static int coinWorth = 0;
void OnCollisionEnter(Collision other)
{
if (other.transform.tag == "Coin")
{
Destroy(destroyCoin);
coinWorth = 1;
}
}
}
GameManager 脚本:
using UnityEngine;
using System.Collections;
public class GameManager4 : MonoBehaviour {
Coin coinValue = GetComponent<Coin>().coinWorth;
void Update ()
{
coinValue = Coin.coinWorth;
}
void OnCollisionEnter(Collision other){
if (other.transform.tag == "Complete" && coinValue > 0) {
Application.LoadLevel(1);
}
}
}
【问题讨论】:
-
如果有人对我的问题有任何疑问,请随时提问