I’m brand new to any type of programming. I’m trying to follow a tutorial and then morph it into my needs.(tutorials on making game boards are very slim).
So this code allows the list of buttons to be interactable once a button has been toggled. I’d like to remove the toggle and make the button list interactable based on a dice roll. The dice roll is already in its own script and I’m passing the roll result into the game controller script. Say we’re calling it finalSide.
void SetBoardInteractable(bool toggle)
{
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i].GetComponentInParent<Button>().interactable = toggle;
}
}
I figure I need to do a series of if statements for the roll results but I don’t know the syntax to make it work. In plain English it would be:
if finalSide is 1 then make buttonListOne interactable
if finalSide is 2 then make buttonListTwo interactable… and so on for all 6 sides.
I’ve watched tutorials, many. I’ve taken an udemy course. It’s not making sense for me yet. If I don’t get someone talking about the exact thing I need I don’t know how to morph it into my specific situation.
You need some tutorial on using arrays in general and in Unity inspector. What you want is a toggle array and use dice roll as array index. One of such tutrials is in C# Fundamentals section here https://www.udemy.com/course/make-your-first-2d-game-with-unity-c-beginner-course/, altrough is hidden behind a paywall. But arrays are fundamental programming topic and there are plenty free tutorial on the C# arrays and using arrays in Unity.
Well I got this to behave how I want but it requires clicking a button in my scene and the finalZoneSide right now is a public int that I change in the inspector to test it. It’s working fine that way. But now I want to remove the button click and replace it with the dice results. The dice results is in a separate script.
You’ll want to get a reference to whatever it is that the button is referencing in the class that does the dice roll, and from there you’ll want to call the function the button calls with a parameter that tells it what the dice came out to be. (I hope that sentence makes sense)
If you would post the full class and not just the part you don’t understand we can understand whats going on better
Well this thread kinda changed into a different question that I’ve been asking here, https://discussions.unity.com/t/772628/12 . The help has run dry at the moment. I probably shouldn’t cross-post the same question. If you do go to that thread I’d advise starting at the end.
I think my scripts are doing what you suggested. I just can’t get the receiving script to see each time the dice is rolled.