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 /
This question was closed Nov 07, 2013 at 09:32 PM by iamthecoolguy11 for the following reason:

time

avatar image
0
Question by iamthecoolguy11 · Nov 04, 2013 at 01:57 AM · c#functionsendmessagecall

What is the best way to call a function from another script

I keep running in to this problem with send message and such because sometimes it works sometimes it doesn't work. All i need is some demonstrations of ways to use send message in a better way or eny other thing that is simpler to call a function from one script to a different one.

Comment
Add comment · Show 1
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 alok1974 · Nov 04, 2013 at 03:39 AM 1
Share

The most efficient way would be to implement events. You can broadcast events and all subscribers to those event will listen and act accordingly. They are preferable because of low overheads and easy script maintainability and organization.

Here is the official unity tutorial on events.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by JamieSinn · Nov 04, 2013 at 02:07 AM

In c# it would be to make the method public or static or even both.

eg... public static void SomeMethod() {

 }
 
 
Comment
Add comment · Show 2 · 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 iamthecoolguy11 · Nov 04, 2013 at 02:08 AM 0
Share

yes i have it as public but what is the best way to set up a sendmessage?

avatar image DannyB · Nov 04, 2013 at 01:59 PM 0
Share

Why do you insist on using Send$$anonymous$$essage? It is probably the worst option of them all and unless you have a good reason for using it, you can easily avoid it. If your methods are public, you can simply call them from wherever you want.

Now as mentioned by the commenter above, depending on your specific use case, you may be looking for a way to broadcast events to several objects, and in this case it would probably be best to use events.

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is calling a function wrong? 2 Answers

call function with same name + number 1 Answer

How can I call a method from another script? 3 Answers

Sending a message from javascript to C# 1 Answer

Multiple Cars not working 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