【发布时间】:2016-08-26 07:15:10
【问题描述】:
以下示例运行良好,但错误索引超出范围。有谁知道我该如何解决?
我的另一个问题是我无法在触摸位置初始化对象。谢谢
void Update ()
{
goldDisplay.text = "Gold " + gold;
if (Input.GetKeyDown(KeyCode.Space) || Input.GetTouch(0).phase == TouchPhase.Began) {
int rarityRoll = UnityEngine.Random.Range (0, 100);
if (rarityRoll < 99) {
// choose something from common
int roll = UnityEngine.Random.Range (0, commons.Length);
// instantiate
Instantiate (commons [roll].componentObjc, new Vector3(0,0,1), transform.rotation);
} else {
int roll = UnityEngine.Random.Range (0, rares.Length);
// instantiate
Instantiate (rares [roll].componentObjc, new Vector3(0,0,1), transform.rotation);
}
}
}
【问题讨论】:
-
哪一行出错了?
-
什么是稀有的 [roll].componentObjc ?你编程一个类操作符?或者你想写rares[roll].gameObject
-
错误所在的行是... if (Input.GetKeyDown(KeyCode.Space) || Input.GetTouch(0).phase == TouchPhase.Began) {
-
commons [roll] .componentObjc 或稀有 [roll] .componentObjc。基本上是两个列表。一个包含稀有物品和其他常见物品。在这种情况下,第一个做一个随机列表。然后选择一个列表,它返回以使另一个随机对象进入该列表..对不起,我的英语,但我在谷歌上翻译......
标签: indexing touch screen bounds out