Answer the question
In order to leave comments, you need to log in
Use SendMessage or is there an alternative?
I was interested in the question of whether to use SendMessage, I found information on one forum that it is slower than GetComponent. They also suggested using an alternative event system
wiki.unity3d.com/index.php/Advanced_CSharp_Messeng... In
general, I liked the system. A single method can be called from anywhere without accessing the component directly.
But this system has one disadvantage: you cannot call all methods with the same name. And SendMessage allows you to call all methods with the same name inherited from MonoBehaviour.
Actually, what I need this for: when one method has finished its work, it tells all the methods that are waiting for it to finish that it has finished working and can pass some parameters to all these dependent methods.
Answer the question
In order to leave comments, you need to log in
You need classic events.
class Enemy{void Start(){Player.Spawn+=StartAttack;}}
class Player{event someDelegate Spawn;}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question