4

I'm trying to create a wrapper around a logging method (Debug.Log) in Unity3d. What I want to do is declare a variable inside whatever class I happen to be working on to shorthand MyDebug.Log('something') into just L('something'). My problem is I can't figure out how to actually store a reference to the method like that.

apxcode
  • 7,696
  • 7
  • 30
  • 41
Joren
  • 9,623
  • 19
  • 63
  • 104

2 Answers2

7

Try this:

Action<string> L = MyDebug.Log;

http://msdn.microsoft.com/en-us/library/018hxwa8.aspx

manojlds
  • 290,304
  • 63
  • 469
  • 417
1

You can use a Action<T> delegate for this. Just use a generic one with how many type parameters you need.

Femaref
  • 60,705
  • 7
  • 138
  • 176