[有一个骰子,我的游戏中有4个玩家。我不介意四次掷骰子。但是当我第五次掷骰子时,玩家不再移动。我该怎么办?让玩家再次移动?
Private IENumerator RollTheDice ()
{
coroutineAllowed = false ;
int RandomDiceSide = 0;
for (int i = 0 ; i <= 20 ; i++)
{
randomDiceSide = Random. Range(0,6);
rend. sprite = diceSides[randomDiceSide];
yield return new WaitForSeconds(0,05f);
}
sıngle4gc.diceSideThrown = randomDiceSide + 1;
if (maxPlayers > whosTurn)
whosTurn = 1;
sıngle4gc.MovePlayer (whosTurn);
whosTurn = whosTurn + 1;
coroutineAllowed = true;
yield return = 0;
}
使用System.Collections;使用UnityEngine;
公共类s4dıce:MonoBehaviour {
private Sprite[] diceSides;
private SpriteRenderer rend;
private int whosTurn = 1;
private bool coroutineAllowed = true;
public int maxPlayers = 2;
// Use this for initialization
private void Start () {
rend = GetComponent<SpriteRenderer>();
diceSides = Resources.LoadAll<Sprite>("DiceSides/");
rend.sprite = diceSides[5];
}
private void OnMouseDown()
{
if (!sıngle4gc.gameOver && coroutineAllowed)
StartCoroutine("RollTheDice");
}
private IEnumerator RollTheDice()
{
coroutineAllowed = false;
int randomDiceSide = 0;
for (int i = 0; i <= 20; i++)
{
randomDiceSide = Random.Range(0, 6);
rend.sprite = diceSides[randomDiceSide];
yield return new WaitForSeconds(0.05f);
}
sıngle4gc.diceSideThrown = randomDiceSide + 1;
if (maxPlayers > whosTurn)
whosTurn = 1;
sıngle4gc.MovePlayer (whosTurn);
whosTurn = whosTurn + 1;
coroutineAllowed = true;
yield return 0;
}
}