Hello, I am making a simple scriptableobject inventory to store the objects of a in-game store.
All was good and wall until it came to the part where I need to instantiate all of the objects from that list and it only instantiates the last one from the list no matter what I tell it to do.
For example I try doing this:
public List<GameObject> gameStoreInventory = new List<GameObject>();
public GameDatabase gameDatabase;
public GameObject slotHolder;
private void Start()
{
PopulateGames();
}
public void PopulateGames()
{
GameObject obj = Instantiate(gameDatabase.games[0].GamePrefab) as GameObject;
gameStoreInventory.Add(obj);
obj.transform.SetParent(slotHolder.transform, false);
}
}
And I’m trying to instantiate the first item in the list but for some reason the last time in the list would always instantiate instead.
The scriptableobject script is this one:
[CreateAssetMenu(menuName = "New Game Database")]
public class GameDatabase : ScriptableObject
{
public List<Games> games = new List<Games>();
public enum GameType { Action, Adventure, RPG, Puzzle, FPS, RTS };
public enum GameQuality { Bad, Decent, Good };
[System.Serializable]
public class Games
{
public GameObject GamePrefab;
public string Name;
public string Description;
public GameQuality GameQuality;
public GameType GameType;
public string Review;
public int Cost;
}
}
And every item that is set in that list has this script attached to it:
public class Game : MonoBehaviour
{
public Text Name;
public Text Description;
public Text Quality;
public Text Genre;
public Text Review;
public Text Cost;
public GameObject GamePrefab;
public GameObject tooltip;
public GamesManager gamesManager;
private void Start()
{
gamesManager = GameObject.Find("Game Store Menu").GetComponent<GamesManager>();
}
private void Update()
{
for (int i = 0; i < gamesManager.gameDatabase.games.Count; i++)
{
Name.text = gamesManager.gameDatabase.games*.Name;*
_ Description.text = gamesManager.gameDatabase.games*.Description;_
_ Quality.text = gamesManager.gameDatabase.games.GameQuality.ToString();
Genre.text = gamesManager.gameDatabase.games.GameType.ToString();
Review.text = gamesManager.gameDatabase.games.Review;
Cost.text = gamesManager.gameDatabase.games.Cost.ToString();
GamePrefab = gamesManager.gameDatabase.games.GamePrefab;
}
}*_
This is how the scriptableobject list looks like in the inspector:
[123432-example.png|123432]
And this is how it look’s like I explained above where no matter what I do the last item is always being displayed:
[123433-example2.png*|123433]*
*
*
Does anyone have any tip’s on how to fix this? What I doing something wrong?
Thanks in advance!