Hello
Simple.
SendMessage send an action to a gameObject. but… how can it works if my function its private?
I mean, i have: void test() {} that should be a Private function.
i understand that in C# if you dont put public than its automatic private (int Number ← same as private int Number). so in a function it should works the same.
So… i dont get it, should i put private or not?? SenMessage access anykind of methods?
I suspect SendMessage will work on private functions - though a quick test will confirm or deny that.
The thing to note is that SendMessage uses advanced behind the scene magic called reflection. Reflection is useful in certain circumstance, but requires a very strong understanding of C# .Net - far beyond that of a beginner. Suffice to say, it can read your code and ignore public/private restrictions.
SendMessage works just fine on private members.
SendMessage doesn’t access the member using mono/.net access modifiers. It ignores it completely. It’s using reflection to do so, and reflection doesn’t care about access modifiers (though I’m not sure if it uses Mono’s reflection library).
Do note, access modifiers aren’t strict in a security sense, it’s strict in the paradigm sense. The language enforces its own strictness to allow you to accomplish certain tasks with in the paradigm you’re writing (object-oriented in this case). But once compiled… really the code is all there and exists in memory. You just need to find out at what register it’s located and start processing it…
It’s just like in C++, you can call the member private all you want, but if you know the address where your class is located, and you know the position in said class where the function is located, you can run it.