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 Brijac · Apr 02, 2021 at 08:37 PM · buttoneffect

How to make a beating/pulsating button effect

So I would like to make a button like this on the image but I would like it to pulsate or beat like a beating heart all the time, even in the idle. The button will be for a mobile game so it should have that effect all the time. Anyone know how I can do this?

alt text

play-button.png (12.5 kB)
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
1
Best Answer

Answer by Llama_w_2Ls · Apr 02, 2021 at 09:47 PM

Here's some untested code but it should work. It essentially expands the size of the button rapidly twice, then returns it to its original size, like a heartbeat. You can also control its speed and pulse strength:

 public class HeartBeat : MonoBehaviour
 {
     public float Strength;
     public float Speed;
 
     void Start()
     {
         StartCoroutine(Pulse());
     }
 
     IEnumerator Pulse()
     {
         // Loops forever
         while (true)
         {
             float timer = 0f;
             float originalSize = transform.localScale.x;
 
             // Heart beat twice
             for (int i = 0; i < 2; i++)
             {
                 // Zoom in
                 while (timer < 0.1f)
                 {
                     yield return new WaitForEndOfFrame();
                     timer += Time.deltaTime;
 
                     transform.localScale = new Vector3
                     (
                         transform.localScale.x + (Time.deltaTime * Strength * 2),
                         transform.localScale.y + (Time.deltaTime * Strength * 2)
                     );
                 }
             }
 
             // Return to normal
             while (transform.localScale.x < originalSize)
             {
                 yield return new WaitForEndOfFrame();
 
                 transform.localScale = new Vector3
                 (
                     transform.localScale.x - Time.deltaTime * Strength,
                     transform.localScale.y - Time.deltaTime * Strength
                 );
             }
 
             transform.localScale = new Vector3(originalSize, originalSize);
 
             yield return new WaitForSeconds(Speed);
         }
     }
 }

@Brijac

Comment
Add comment · Show 6 · 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 Brijac · Apr 03, 2021 at 08:53 AM 0
Share

Hey man, thanks for answering. This works but it has a delay when the button grows and then goes back to normal size like this:

Grow->Back to normal->Delay->Grow->Back to normal...

How to get rid of that delay so the button constantly goes "grow-backtonormal-grow-backtonormal..."?

avatar image Llama_w_2Ls Brijac · Apr 03, 2021 at 09:42 AM 0
Share

I believe that you would just set speed to 0, to make sure there's no delay

avatar image Brijac Llama_w_2Ls · Apr 03, 2021 at 10:00 AM 0
Share

Yeah that did it lol, didn't even thought about it.

I don't wanna bother you but if you have will and time.. now that button grow looks too fast if you know what I mean, it just pops up and goes back fast so it just doesn't look good going that fast. Even when I play with the Speed and Strength I can't really get it to go slowly up and then slowly down. Do you know how I could make it work more smoothly?

Show more comments

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

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

Related Questions

Gui Button zoom 1 Answer

enable Blur effect when Esc button pressed (Windows Phone 8) 1 Answer

Cooldown effect in a button 4 Answers

create a button with name and text for every game object with tag 0 Answers

Changing animation using with UI button 0 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