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 coral_push · Apr 02, 2014 at 03:05 PM · timerrendererenabled

Trying to get object to blink (speed acording to timer)

I'm trying to get a cube object to blink by using renderer.enabled, and have the speed it blinks be measured by a timer. For example the red coins in Mario games. I want it to slowly start to blink faster as it gets closer to the time limit i have set up. Anyone know the best way to go about it?

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

2 Replies

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

Answer by robertbu · Apr 02, 2014 at 04:11 PM

'Best is always open to interpretation, but here is some starter code:

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour {
 
     public float time = 30.0f;
     public float maxInterval = 1.2f;
     public float minInterval = 0.2f;
     
     private float interval = 1.0f;
     private float timer    = 30.0f;
     
     void Start() {
         timer = time;
     }
     
     void Update () {
         interval = minInterval + timer / time * (maxInterval - minInterval);
         timer -= Time.deltaTime;
         if (timer < 0.0f) timer = 0.0f; 
         renderer.enabled = Mathf.PingPong(Time.time, interval) > (interval / 2.0f);
     }
 }

 
Comment
Add comment · Show 3 · 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 AlucardJay · Apr 02, 2014 at 04:52 PM 1
Share

holy math Batman, that's some pretty intense 'starter' code ;)

just to mention, the OP has tagged C#

avatar image coral_push · Apr 04, 2014 at 05:11 AM 0
Share

Thanks for the help to everyone who responded ! Got it to work well.

avatar image araz01 · Feb 24, 2020 at 11:47 PM 0
Share

Transform blinkOfTransform;

transform.position = blinkOfTransform.position;

or

use rigidbody force, or use vector3 forward with either + or - on 25 speed, etc, but transform wil lbe much beter jsut find the code

avatar image
0

Answer by patrik-org · Apr 02, 2014 at 05:05 PM

Perhaps something like:

 blinkSpeed = startSpeed + totalSpeedIncrease * timeElapsed / maxTimeElapsed; // blink speeds measured in blinks per second
 
 t += Time.deltaTime * blinkSpeed;
 if (t >= 1)
 {
     t = 0;
     // switch renderer.enabled
 }
 
Comment
Add comment · 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

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

22 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

Related Questions

renderer.enabled question 2 Answers

Mesh Renderer not showing in scene, disabled in Inspector, but debug says it's enabled? 1 Answer

Turn off renderer untill key pressed again 0 Answers

Muzzle flash acting weird 0 Answers

renderer.enabled false 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