Hello everyone,
i am kind of struggling to make this simple code running. I am not a programmer but i am slowly learning while making a 3D game.
The problem should be quite simple to solve hopefully. I will give you a quick briefing following by the code: The game at the start by means of a simple script will select randomly 3 objects from a series of gameobjects i built on the hierarchy. the next step is to put these 3 objects into a List (made by a second script) i will use for other purpose like Re-randomization of the objects to be shown in the map.
here is where I am struggling. I can’t store the 3 objects into a new list. I probably missing something to make the 2 scripts comunicate to each other properly so that the first code will generate the 3 objects and the second Script will take those objects and store them into a list.
FIRST SCRIPT (GENERATE THE OBJECT)
MyInvento Inventario;
public GameObject spawnPoint;
public GameObject[] gemme;
public Transform[] NewPos;
public GameObject currentGem;
int index;
void Start()
{
index = Random.Range(0, gemme.Length);
currentGem = gemme[index];
currentGem.transform.position = spawnPoint.transform.position;
currentGem.SetActive(true);
SECOND SCRIPT (STORE IT INTO THE NEW LIST)
public class MyInvento : provaRandom
{
#region Singleton
public static MyInvento instance;
void Awake()
{
if(instance != null)
{
Debug.Log("no good");
}
instance= this;
}
#endregion
provaRandom gemma;
public List<GameObject> MyGem = new List<GameObject>();
public void AddItem ()
{
MyGem.Add(gemma.currentGem);
}