Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 stuthemoo · Sep 02, 2011 at 08:14 AM · updatemessageholdsend

SendMessage every second?

Hi,

I'm using "SendMessage("decrease", rate, SendMessageOptions.DontRequireReceiver)" within an update function but I don't want it to occur every frame, instead only once a second. Also I only want it to be sent while the jump button is held down.

How can I do this?

Thanks, Stu

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 stuthemoo · Sep 02, 2011 at 09:11 AM 0
Share

I would also like the var "rate" to be larger, the faster the rigidbody is going. Something like "rate * rigidbody.velocity" is this possible?

2 Replies

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

Answer by save · Sep 02, 2011 at 08:35 AM

You should invoke the call for timed functions, running a function every frame will still eat some CPU.

 function Start () {
     InvokeRepeating("sendDecreaseMessage", 0, 1);
 }
 
 function sendDecreaseMessage () {
     SendMessage("decrease", rate, SendMessageOptions.DontRequireReceiver);
 }
Comment
Add comment · Show 7 · 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 save · Sep 02, 2011 at 08:38 AM 0
Share

$$anonymous$$eep in $$anonymous$$d that Send$$anonymous$$essage is more expensive than a direct call to the GameObject(s).

avatar image stuthemoo · Sep 02, 2011 at 08:47 AM 0
Share

direct call?

avatar image save · Sep 02, 2011 at 08:52 AM 0
Share

Cache the target component and access it directly (if it's possible):

 private var target : theComponent;
 target = GetComponent(theComponent);

Then you can use

 target.decrease();
avatar image stuthemoo · Sep 02, 2011 at 09:35 AM 0
Share

Thanks for your help save. Just one more thing. I would also like the var "rate" to be larger, the faster the rigidbody is going. Something like "rate * rigidbody.velocity" is this possible?

avatar image save · Sep 02, 2011 at 09:41 AM 0
Share

Yeah sure it's very possible, just keep in $$anonymous$$d that you should clamp the rate value to a maximum.

What is it exactly you want to do? There might be better solutions for this.

Show more comments
avatar image
-1

Answer by Ludiares.du · Sep 02, 2011 at 08:31 AM

 function Update()
 {
    Send();
 }
 function Send()
 {
      yield WaitForSeconds(1);
      if(Input.GetButton("Jump"))
      {
           SendMessage("decrease", rate, SendMessageOptions.DontRequireReceiver);
      }
 }
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 Eric5h5 · Sep 02, 2011 at 09:36 AM 0
Share

That won't work. It will start a new instance of the coroutine every frame.

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

6 People are following this question.

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

Related Questions

Pass Enum To Function Parameter 2 Answers

BroadcastMessage 1 Answer

How to Send Message to other GameObject 3 Answers

Flame Thrower - Particle Collision Help 1 Answer

How do i Specify a Receiver for a Send Message Function? 2 Answers


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