Hey guys,
I’ll just get straight to the point. I have an itemManager with two lists. One list contains all of the resources in the game, the other contains all the resources that the player currently has. Both lists should contain scriptableObjects, although only the resourceList has resources while the currentResourceList is empty.
When the player presses a button, AddResource() is called by another script. this method chooses a random resource from the list and returns it for another script to pick up and instantiate. AddResource() is also supposed to add the resource to the list of current resources but it doesn’t. That’s the problem I can’t find a solution for.
The method returns a resource perfectly, but I can’t get the resource to be added to the currentResources List.
Any help would be greatly appreciated.
thanks in advance,
Lajos
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemManager : MonoBehaviour
{
public List<Resource> resourceList;
public List<Resource> playerResourceList = new List<Resource>();
private static ItemManager instance;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public Resource AddResource()
{
Resource resourceToAdd = resourceList[Random.Range(0, resourceList.Count)];
playerResourceList.Add(resourceToAdd);
return resourceToAdd;
}
}