You can’t “copy” a function. C# is not a dynamic scripting language. Every function / method is compiled. However what you want is called a delegate. A delegate is like a “function pointer”. It allows you to assign a function with the same signature to a delegate variable. Then you can use the variable to execute the assigned function:
You can define a delegate type like this:
public delegate RETURNTYPE MyDelegateType(PARAMETERS);
There is a predefined type “Action” which equals:
public delegate void Action();
To define a delegate variable you simply use the delegate as type:
public MyDelegateType variableName;
So in your case you can do:
public System.Action attack1;
void OnGUI()
{
if (GUI.button(new Rect(0,0,100,100),"att01"))
{
attack1 = gameObject.GetComponent<Warrior>().att01;
}
}