I am making a Yahtzee game. I have 3 files one has the rolling of the dice function and a list of sprites representing the dice face and a list of buttons representing each individual dice. :
using UnityEngine;
using UnityEngine.UI;
public class RollRandom : MonoBehaviour
{
//dice for dice roller
public int dice1;
public int dice2;
public int dice3;
public int dice4;
public int dice5;
//faces
public Sprite[] diceFaces;
//GameObjects
public Button[] diceSprites;
void Start()
{
dice1 = Random.Range(1, 7);
dice2 = Random.Range(1, 7);
dice3 = Random.Range(1, 7);
dice4 = Random.Range(1, 7);
dice5 = Random.Range(1, 7);
GameObject SelectionManager = GameObject.Find("SelectionManager");
SelectDice SelectDice = SelectionManager.GetComponent<SelectDice>();
if (SelectDice.selected1 == false)
{
diceSprites[0].image.sprite = diceFaces[dice1 - 1];
}
if (SelectDice.selected2 == false)
{
diceSprites[1].image.sprite = diceFaces[dice2 - 1];
}
if (SelectDice.selected3 == false)
{
diceSprites[2].image.sprite = diceFaces[dice3 - 1];
}
if (SelectDice.selected4 == false)
{
diceSprites[3].image.sprite = diceFaces[dice4 - 1];
}
if (SelectDice.selected5 == false)
{
diceSprites[4].image.sprite = diceFaces[dice5 - 1];
}
Debug.Log("Started");
}
public void GenerateNumber() {
dice1 = Random.Range(1, 7);
dice2 = Random.Range(1, 7);
dice3 = Random.Range(1, 7);
dice4 = Random.Range(1, 7);
dice5 = Random.Range(1, 7);
int z = 0;
GameObject SelectionManager = GameObject.Find("SelectionManager");
SelectDice SelectDice = SelectionManager.GetComponent<SelectDice>();
if (SelectDice.selected1 == false)
{
diceSprites[0].image.sprite = diceFaces[dice1 - 1];
}
if (SelectDice.selected2 == false)
{
diceSprites[1].image.sprite = diceFaces[dice2 - 1];
}
if (SelectDice.selected3 == false)
{
diceSprites[2].image.sprite = diceFaces[dice3 - 1];
}
if (SelectDice.selected4 == false)
{
diceSprites[3].image.sprite = diceFaces[dice4 - 1];
}
if (SelectDice.selected5 == false)
{
diceSprites[4].image.sprite = diceFaces[dice5 - 1];
}
int index = System.Array.FindIndex(diceFaces, 0, 5, );
}
}
and another file to select dice t hold and not roll with selecting the dice but that one is irrelevant in this case. but the third one is to manage the playing of the dice in certain places for points.
using UnityEngine;
public class PlayManager : MonoBehaviour
{
public int[] faceValue;
public UnityEngine.UI.Button dice1;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Manager()
{
GameObject RNGManager = GameObject.Find("RNGManager");
RollRandom rollRandom = RNGManager.GetComponent<RollRandom>();
int index = rollRandom.diceFaces.FindIndex();
}
}
what I need to do is return the index of that diceFaces list for each dice so I can add 1 to it and get the value of it. what do I put in the parenthesis after int index = rollRandom.diceFaces.FindIndex();