Search a Variable using a String

Hi all,

I’ve seen this code in HOTween plugin:

HOTween.To(myObject, 1, "myProperty", 2);

This will change the variable myProperty inside myObject. For example you can write (object.transform,... , "localPosition",...) and it will change the localPosition vector of the transform.

Any ideas about how that can be achieved? I mean getting a real variable from a string, as using Find() but for vars instead of gameobjects


Sure, but it is SLOW.

 myObject.GetType().GetField("xxxx").SetValue(myObject, something); //Fields

 myObject.GetType().GetProperty("xxxx").SetValue(myObject, something, null); //Properties

Obviously the opposite is GetValue().