Hi guys,
In my current project I’d like to pass on parameters in a dynamic fashion. I don’t want to use overloads since this makes the code extremely ugly and long for something that should really be very compact. I believe in C# 4.0 one can use the “dynamic” keyword to achieve this, but I am not sure how to make this happen in Unity’s C# 3.5.
In my specific case, I’d like to call a sync function which then executes a bunch of RPC calls depending on the dynamic parameter. This parameter could take a variety of types/values, e.g. string, float, Vector2, Vector3, etc.
Example:
private void Sync(string function, int id, int type, dynamic val) {
if (val is float) ......
}
As mentioned, “dynamic” is unfortunately not possible in Unity at this point. What would be another, yet efficient way to achieve this?