I want to get multiple string values(selectedNameand
selectedCurrency
) individually from public override string ToString()
below. How do I go on about it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Country", menuName = "Country/Country", order = 0)]
public class country : ScriptableObject
{
[System.Serializable]
public class Item
{
public string Name;
public string Currency;
public string Capital;
public string[] City;
public override string ToString()
{
string selectedName = this.name;
string selectedCurrency = this.currency;
return selectedName + selectedCurrency;
}
}
public Item[] m_Items;
public Item PickRandomly()
{
int index = Random.Range(0, m_Items.Length);
return m_Items[index];
}
}
I need to use the selected string values in the script below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController: MonoBehaviour
{ public country country; //This is the scriptable object country
public Text countryText;
public Text currencyText;
void Start(){
countryText.text = country.PickRandomly().ToString(); // This is where I need the country name string to show up.
currencyText.text = country.PickRandomly().ToString(); // This is where I need the currency string to show up.
}
}
Right now it just displays a random country name and currency for example USA USD in both the fields.