Can u make a list of methods that get randomly picked from a list?
i want to have a deck of cards that are "random events" , What ive seen from arrays and such are more about input and strings.
this will just be simply "ouch u got a stick in eye -10 health" So each method will have a few functions from add/subtracting player stat values to adding objects to their inventory, i was initially just going to use a random int and do like 80 if statements sorta like
if(choice == 4)
{
DoTheThing();
}
if(choice == 5)
{
DoADifferentThing();
{
if(choice ==6)
{
DoATerribleThing();
}
and so on and so on. but i cant help but feel theres probably a better way to do this but im not seeing anything. So i thought id come here and see.
Answer by jimmiewalker653 · Nov 26, 2020 at 02:17 PM
void PickRandomChoice() { choice= Random.Range(0,6); if (choice==1) DoTheThing(); else if (choice==2) DoADifferentThing(); else if (choice==3) DoATerribleThing(); }
Another way you could set it up is to have 2 different method groups. One method group would tell the player where the damage occurred and the 2nd would tell the player how much damage they take. Overall, the if and else if statements would be the best to use to my knowledge. However, by setting up 2 or more method groups, you could cut down from 80 if statements to no more than 40.
Your answer
![](https://koobas.hobune.stream/wayback/20220613020546im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calling a method twice in Start without overwriting 0 Answers
How can I add functions via a scriptswizzard variable? 0 Answers
Interval of x seconds between two method invokes. 0 Answers
Problems with Intellisense,Intellisense for Unity specific components etc. 0 Answers
Unity returns InvalidCastException when attempting to run a method from another file 2 Answers