Quantcast
Channel: Answers for "if statement for 6 ints help C#"
Viewing all articles
Browse latest Browse all 4

Answer by Bunny83

$
0
0
IF you need to perform such an analyse on those values you really should replace them in an array or this is going to be messy. This would be one simplification: public int[] values = new int[6]; void Update() { for (int i = 0; i currentV) { currentIndex = i; currentV = values[i]; } } return currentIndex; } So instead of having 6 individual integers we use one array with 6 values. FindMax() will return the index of the array element which holds the largest value. You could define another array with level names which should be loaded for each value: public string[] levelNames; Fill in the 6 level names in the inspector. You can get the level name like this: int index = FindMax(); string levelName = levelNames[index]; -------------------------------------------------------------------------- Since it's easy to mess up those two arrays (you always need as many level names as integer values in the other array), it might be useful to bundle your value with the level name and maybe even a string that describes the value in case you want to show those 6 values to the user: [System.Serializable] public class CustomValue { public string Name; // name of the value, could be "neutral", "direct", ... public int Value; // the actual value public string LevelName; // will hold the level name associated with this value } // edit those in the inspector. Set the size to 6 and fill in the names and the // associated level names. public CustomValue[] values; void Update() { for (int i = 0; i current.Value) current = values[i]; } return current; } Now FindMax returns an instance of custom class. This has several advantages. We can directly access the Value. it's Name and the LevelName. string levelName = FindMax().LevelName; Now the value is directly coupled with the level name that should be loaded.

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images