I would like to know if there is a way to call an object from a string.
Here is an example:
public class Butao
{
public string _Name_;
public float _Price_;
public Butao(string name, float price)
{
_Name_ = name;
_Price_ = price;
}
}
public class DataBase : MonoBehaviour
{
string id;
private void Start()
{
var bar1 = new Butao("", 0);
var bar2 = new Butao("", 0);
var bar3 = new Butao("", 0);
}
}
I'm working on UnityEngine but it should not differentiate much from "pure" C #, because that's what I'll actually use in this script, not Unity functions. What I would like to do was through a string, the string id, and pass it directly and call the object with that name. For example:
If id equals "Bar1", I wanted to edit the properties of Bar1, that is,
Bar1.Name = "Alterado";
Bar1.Price = 2
and so on.
The problem is that I have 60 different objects and could not see one by one, hence automating the process.