Quantcast
Channel: Answers for "What's the difference between SendMessage and GetComponent?"
Viewing all articles
Browse latest Browse all 6

Answer by Squeegy

$
0
0

I would assume that

  1. There is no functional difference as long as only one script implements that method.
  2. GetComponent would be faster since it does not have to look for method on all attached components.

I would use SendMessage when implementing a protocol of messages that many different scripts can optionally repsond to. This allows you to have a good deal of flexibility. You can simply tell an object to DoStuff without having to know what kind of object it is or what scripts are on it. It is left up to the object itself to know how to do it's own stuff.

But if enemies are the only things that you ApplyDamage to, it makes more sense to call it directly. Use the SendMessage route if you want to have a variety of scripts trigger when you ApplyDamage to an object.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>