Hi! And sorry for my eng. I just learning to code and stuck with that problem - I have few buttons with some info about cost and level of selling properties. Each of them have next code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BuyBtns : MonoBehaviour
{
public SaveManager sData;
public Text lvl;
public Text buyCost;
public string varLvl; // I manually write the required variable name for each button in inspector
public string varCost; // And here too
void Start ()
{
lvl = gameObject.transform.GetChild(1).GetComponent();
buyCost = gameObject.transform.GetChild(2).GetComponent();
sData = GameObject.Find("PlayZone").GetComponent();
}
public void RefreshInfo()
{
var lvlresult = sData.sv.GetType().GetField(varLvl).GetValue(sData.sv);
lvl.text = lvlresult.ToString();
}
}
I tried many different options for last method and this most successful with non-array variables. But i need to get value from array with index like [sData.sv.choosenShip] ?
However, i found another way. More combrous. But this gap in my knowledge been bugging me.
↧