Hi, here is my problem:
I have a list of names, prices etc… in another script. In first script I make 4 gui buttons and once is button clicked I need to get an number for item I just clicked (hope you guys understand, I will also attach picture):
First script (here I acces my lists):
// Accesing other script
GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
ScriptActors scriptActors = mainCamera.GetComponent<ScriptActors>();
int heightGuiPosOffSet = 0;
// Here we want to show all of our actors
for (int i = 0; i < scriptActors.names.Count; i++)
{
heightGuiPosOffSet += 100; // Offset for our buttons
// Show actors available to contract
if (GUI.Button(new Rect(Screen.width / 2 - 225, Screen.height / 2 + heightGuiPosOffSet - 300, 450, 100), "Name: " + scriptActors.Name(i) + ", " + "Age: " + scriptActors.Age(i) + ", " + "Focus: " + scriptActors.Focus(i) + ", " + "Price: " + scriptActors.Price(i)))
{
}
}
Here is my second script (with my lists):
public List<string> names = new List<string>{"Johny Fapp", "Angelina Trollie", "Peter Smooth", "Leonardo Mario"};
public List<int> ages = new List<int>{18, 22, 54, 45};
public List<string> focuses = new List<string>{"Action Films", "Documentary", "Sci-fi Films", "Nasty Movies"};
public List<int> prices = new List<int>{10000, 2300, 2000, 60000};
public string Name(int nameIndex)
{
return names[nameIndex];
}
public int Age(int ageIndex)
{
return ages[ageIndex];
}
public string Focus(int focusIndex)
{
return focuses[focusIndex];
}
public int Price(int pricesIndex)
{
return prices[pricesIndex];
}
I was also thinking to make it this way:
int actorIndex = 0;
if (GUI.Button(new Rect(Screen.width / 2 + 20, Screen.height / 2 - 100, 100, 50), "NEXT"))
{
actorIndex += 1;
Debug.Log(actorIndex);
}
if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 100, 100, 50), "BACK"))
{
actorIndex -= 1;
Debug.Log(actorIndex);
}
if (GUI.Button(new Rect(Screen.width / 2 - 225, Screen.height / 2 - 200, 450, 100), "Name: " + scriptActors.Name(actorIndex) + ", " + "Age: " + scriptActors.Age(actorIndex) + ", " + "Focus: " + scriptActors.Focus(actorIndex) + ", " + "Price: " + scriptActors.Price(actorIndex)))
{
}
But I don’t know why actorIndex is not changing though

