1
I wonder if there’s 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 am working on Unityengine but should not differentiate much from c# "pure", because it is what I will actually use in this script, and not functions of Unity. What I would like to do is 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, ie,
Bar1.Name = "Alterado";
Bar1.Price = 2
and so on.
The problem is I have 60 different objects and it wouldn’t do to see one by one, then automate the process.
If id equals "Bar1". You cannot create a property
Idand assign"Bar1"to her?– igventurelli
That’s what I ended up doing, joining the code with Thiago Lunardi’s
– André Moreira