I have been trying to figure out how to get information from the itemList class at the bottom of the code using another script, but I have not been able to wrap my head around the issue. Do any of you guys have any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class masterList : MonoBehaviour
{
public itemList[] itemLists = new itemList[5];
}
[System.Serializable]
public class itemList
{
public Transform[] prefabs = new Transform[5];
}
if this is a “master list” and you only have one occurrence of your itemLists then why not just make it static?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class masterList : MonoBehaviour
{
public static itemList[] itemLists = new itemList[5];
}
[System.Serializable]
public class itemList
{
public Transform[] prefabs = new Transform[5];
}
then you can access it anywhere from any script by simply saying:
masterList.itemLists
alternatively you can use Getcomponent
GameObject go;
// go should be the game object the script is attached to
masterList myscript = go.GetComponent<masterList>();
// now access the script like this:
myscript.somevariable = whatever;