- Home /
How to execute a function which is implemented in .NET when I have its name as a string?
I wanna execute a function which is implemented in .NET when I have its name as a string.
void Awake(){
string functionName = "print";
//call a function by functionName in some way
}
void print(String str){
//I wanna make this method not to be called.I wanna call MonoBehaviour.print.
}
In this way, I'd not like to execute a function which is implemented by me. How should I do?
Thank you.
The answer is reflection. Google it. I might be back later to post a full answer.
i'm curious about why you'd want to do this. can you provide a use case.
I used to see people do this in JavaScript a lot using eval() - personally I think it's a pretty terrible idea, for robustness, security, and performance reasons...
Answer by Xtro · Jul 24, 2014 at 04:06 PM
SendMessage("print", "parameter here");
more info : http://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html
I do not want to call a function which is implemented by me. I want to call only functions which is implemented in .NET.
Your answer
![](https://koobas.hobune.stream/wayback/20220613154902im_/https://answers.unity.com/themes/thub/images/avi.jpg)