Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by youngapprentice · Feb 27, 2013 at 09:56 PM · javascriptgame designmessaging

Messaging Confusion

Hi, all!

So throughout my game project whenever I want to do damage to an object I have been having the object that gets hit call the function do damage itself on itself. For instance, when an enemy fires, it takes its 'damage' variable and plugs it into the bullet. The player gets the 'damage' variable from the bullet and applies it to itself.

Well, what if I wanted to damage everything onscreen?

One way would be to run a for loop through all of the children of my 'enemy' empty parent object,

But what about using the messaging system?

I have seen others use it, but have never found any practical use of it for myself. When I was programming games with Blender, I used messaging all of the time, but that was simply because it allowed me to not code much (a messaging system was supported in their 'GameLogic' UI ).

Currently, in my project, I have a BUNCH of 'cahching this object's script in the start' and 'using that variable when I need to'. Code can get really cluttered, as some gameObject have to be cached all of the time if I need to access them. I understand that this is not necessary with Messaging.

So...

  • When should I be using the messaging system?

  • How should I use it? (this can be simple)

  • When should I avoid using it and opt for other methods for calling functions on GameObjects?

Thanks! - YA

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mikilo · Feb 27, 2013 at 10:11 PM

Hi!

Using SendMessage() system is heavy. It's not efficient at all.

You can try to use a saved list somewhere, like a game manager. In Start(), you register your unit in the game manager. In OnDestroy(), you unregister your unit from the game manager. If you have to while on every unit, you can simple use the list in the game manager. This is more efficient than SendMessage(), FindObject, GetComponent(). Because don't have to search, it's already ready!

You can take a look at this link: http://unitygems.com/script-interaction1/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image youngapprentice · Mar 02, 2013 at 03:39 PM 0
Share

Hmmm. Alright. I guess I'll just keep on doing what I'm doing then. Thanks.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[En & Fr] Show a message on the screen - Faire apparaître un message sur l’écran 1 Answer

Saving data to xml file (I have the loading down) 0 Answers

Customize a scripted GUI 1 Answer

adding multiple values to single function/variable. 0 Answers

UnityScript to C# conversion help? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges