I wanted to create a custom array that contains both strings and integers to represent the name and amount of an item a player has. While this did work in the inspector, I don't know how to access or change values or add new elements in a custom array during gameplay. The website that I used as a guide had 2 functions, but they unfortunately didn't work. How can I edit a custom array during gameplay?
Here is the minimum required code:
using System;
using System.Collections.Generic;
using UnityEngine;
public class CustomArrayTest: MonoBehaviour
{
[SerializeField] private PlayerScrolls[] playerScrolls;
public void SetValue ()
{
//Function to set a value in the array
}
public SubClass GetValue ()
{
//Function to get a value in the array
}
}
[System.Serializable]
public class PlayerScrolls
{
public int scrollAmount;
public string scrollName;
}
Website I based his code off of: https://owlcation.com/stem/Using-Single-and-Multi-Dimensional-Arrays-in-C-and-Unity3D