I think i’m having trouble understanding what a list that stores GameObjects is, or what it exactly stores…
I was messing around and i tried creating a script that stores gameobjects and then brings them back. But i have no clue how to put them back into the scene. Im having trouble in the “Drop” function
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameObjectListTest : MonoBehaviour
{
public List<GameObject> Inventory = new List<GameObject>();
public GameObject TestCube;
void Start(){
}
void Pickup(List<GameObject> inventorylist, GameObject item){
inventorylist.Add(item);
Destroy(item);
}
void Drop(List<GameObject> inventorylist, int index){
if (inventorylist[index].name != null){
//bring back the item into the scene, or make a replica of the item and put it onto the scene
}
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Tab)){
Pickup(Inventory, TestCube);
Debug.Log(Inventory[0].name);
}
if(Input.GetKeyDown(KeyCode.LeftAlt)){
Drop(Inventory, 0);
Debug.Log(Inventory[0]);
}
}
}
im kind of a newb, and i do not really understand what List stores…