Game body message transmission:
GameObject. SendMessage-send messages to your own scripts
GameObject. BroadcastMessage-send messages to itself and its child
GameObject. SendMessageUpwards-send messages to itself and its parent
PS: GameObject. SendMessageUpwards ("MotherFunction", "Hello ")
You can also use the delegate and event mechanisms in C # To break the structural limitations of the Game objects that transmit messages above.
Dispatcher segment:
Public delegate void EventHandler (GameObject e );
Public event EventHandler MouseOver;
Void OnMouseOver (){
If (MouseOver! = Null ){
MouseOver (this. GameObject );
}
}
Listener segment:
Dispatcher ev = this. GameObject. Find ("Cube"). GetComponent <Dispatcher> ();
Ev. MouseOver + = myFunction;
Void myFunction (GameObject e ){
// E is Dispatcher
}
This article is from the "Better_Power_Wisdom" blog, please be sure to keep this source http://aonaufly.blog.51cto.com/3554853/1283928