這是代碼。我想在Update方法中使用SpwanArrow方法的int randomIndex值。有任何想法嗎?從一種方法獲取int值到另一個C#
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
}
使它成爲一個一流水平的變量。 – juharr
你想用'randomIndex'做什麼? – Romoku