【发布时间】:2017-09-09 18:25:14
【问题描述】:
这里是代码。我想在 Update 方法中使用 SpwanArrow 方法中的 int randomIndex 值。有什么想法吗?
void SpawnArrow()
{
//some code here
int randomIndex = UnityEngine.Random.Range(0, arrows.Length);
GameObject prefab = arrows[randomIndex];
GameObject clone = Instantiate(prefab, new Vector3(0.02F, 2.18F, -1),
Quaternion.identity);
}
void Update()
{
if (randomIndex == 1 && (Input.GetButtonDown("a") == true))
{
ScoreManager.score += scoreValue;
}
//and so on
}
【问题讨论】:
-
使其成为类级变量。
-
你想用
randomIndex做什么?