So i am trying to make a small app for my dad to use as a doctor, and it includes that he can save different kinds of medicin to a list which is displayed in a dropdown menu. When he then opens the app again, the list with the recently added medicin will still be there.
I am used to saving ints and strings to playerprefs, but this is the first time i am trying to save lists.
This is the script i am working on:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour
{
public List<string> medicin = new List<string>() ;
public List<string> savedMedicin = new List<string>() ;
public InputField input;
public Dropdown menu;
void Start()
{
}
void Update()
{
for (int i = 0; i < savedMedicin.Count; i++)
{
PlayerPrefs.GetString("med" + i, savedMedicin*);*
}
}
public void AddToList()
{
medicin.Add(input.text);
for (int i = 0; i < medicin.Count; i++)
{
PlayerPrefs.SetString(“med” + i, medicin*);*
}
menu.ClearOptions();
menu.AddOptions(savedMedicin);
}
}
The script is simple: I have an input field, a dropdown menu and a button.
When i write a name in the inputfield and press the button, the name should get saved and displayed in the dropdown menu. I have tried some different ways, so the script i am showing now may not be the wisest way to go.
Well either way it does not work. I am having trouble saving the list to “med”, and retrieving it again.