- Home /
Question by
Atzig · Jan 25, 2018 at 06:44 PM ·
editorinspectorserializablefor loopcustom class
Logic Problems using for loops
So I have a custom class called Championships:
public class Championship : MonoBehaviour {
[System.Serializable]
public class Championships
{
public string raceName;
public int raceCount; // the number of races in the championship
public int raceIndex; // used by the custom inspector to cycle through the races
}
And a custom inspector/editor for this script (not the entire thing of course):
for (int i = 0; i < championshipScript.championships.Count; i++)
{
// no problems here, just doing some stuff
for (int j = 0; j < championshipScript.championships[i].raceCount; j++)
{
// retrieving some info from another script, works fine
championshipScript.championships[i].raceName = menuManager.menuTracks[championshipScript.championships[i].raceIndex].name;
// displaying that info, again works fine
EditorGUILayout.TextField("Race Name:", championshipScript.championships[j].raceName);
// cycling through the championship script, works fine?
if (GUILayout.Button("<"))
{
if (championshipScript.championships[i].raceIndex > 0)
{
championshipScript.championships[i].raceIndex -= 1;
}
}
The problem is that when cycling through the Championship class with raceIndex
, the info is displayed across other Championships (see the image, highlighted area). So, a big flaw in my logic and I can't figure out the solution.The "<" and ">" buttons should change ONLY the text fields above it but they change others at the same index. Any solutions, tips, advice? I've been stuck on this for a few days now so anything at all would be greatly appreciated.
problem.png
(27.7 kB)
Comment