Using reflection in Unity3D

Hey guys,

I’m building a plugin that affects the in game currency of a game.
Being a plug-in I can’t know what is the name of the class or variable of the “currency” of the specific game. Thus I’m assuming I need reflection.

I’ve tried :
coinsTotal = (int)(scriptWithCoins as typeof(scriptWithCoins)).GetField (“VariableName”).GetValue(typeof(int));

But that doesn’t work.

1 Answer

1

Err no - it wouldn’t :slight_smile:

   scriptWithCoins.GetType().GetField(variableName).GetValue(scriptWithCoins);