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 michael0321 · Aug 28, 2014 at 06:12 PM · blinking

How Do i make the prefab stop blinking

I am trying to get my prefab to stop blinking after 1.5 seconds. How do I do this. Time is still kind of confusing for me as I am really new to unity. Any help would be greatly appreciated.

 using UnityEngine;
 using System.Collections;
 
 public class JmpFlasher : MonoBehaviour {
 
     Material mat;
     public Color color;
     bool isFlashing;
     // Use this for initialization
     void Start () {
         isFlashing = false;
         mat = new Material (Shader.Find("Transparent/Diffuse"));
         mat.color = new Vector4 (color.r,color.g,color.b,1);
         renderer.material = mat;
     }
     
     // Update is called once per frame
     void Update () {
         if(isFlashing)
             mat.color = new Vector4 (color.r,color.g,color.b,(Mathf.Sin (Time.time*8+1)/2));
     }
 
     public void startFlash (){
         isFlashing = true;
     }
 }

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

Answer by Landern · Aug 28, 2014 at 06:14 PM

     public IEnumerator startFlash (){
         isFlashing = true;
         yield return new WaitForSeconds(15);
         isFlashing = false;
     }
Comment
Add comment · Show 4 · 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 michael0321 · Aug 28, 2014 at 06:38 PM 0
Share

I put that in my script to replace the public void startFlash()section of the code but it does not flash at all. is that the wrong place to put it?

Thank you

avatar image TRG96 · Aug 28, 2014 at 06:48 PM 0
Share
 void update()
 {
     startFlash();
     if(isFlashing)
             mat.color = new Vector4 (color.r,color.g,color.b,($$anonymous$$athf.Sin (Time.time*8+1)/2));
 }
 
 public IEnumerator startFlash (){
         isFlashing = true;
         yield return new WaitForSeconds(15);
         isFlashing = false;
     }
 
 That should work.
 
avatar image llnk7 · Aug 28, 2014 at 08:02 PM 0
Share

$$anonymous$$mm correct me if I'm wrong but don't you have to call all IEnumerator functions with:

StartCoroutine(IEnumerator routine);

??

avatar image tanoshimi · Aug 28, 2014 at 08:56 PM 0
Share

You do. You also need a capital "U" in Update :)

avatar image
0

Answer by michael0321 · Aug 28, 2014 at 10:47 PM

Thanks everyone i'll give it a try

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 michael0321 · Aug 28, 2014 at 11:06 PM 0
Share

Thank for the help but the code only turns my prefab into the the color it is supposed to flash and stays that color. here is the code

using UnityEngine; using System.Collections;

public class JmpFlasher : $$anonymous$$onoBehaviour {

 $$anonymous$$aterial mat;
 public Color color;
 public bool isFlashing;
 // Use this for initialization
 void Start () {
     isFlashing = false;
     mat = new $$anonymous$$aterial (Shader.Find("Transparent/Diffuse"));
     mat.color = new Vector4 (color.r,color.g,color.b,1);
     renderer.material = mat;
 }
 
 // Update is called once per frame
 //void Update () {
 //    if(isFlashing)
 //        mat.color = new Vector4 (color.r,color.g,color.b,($$anonymous$$athf.Sin (Time.time*8+1)/2));
 //}

 //public void startFlash (){
 //    isFlashing = true;
 //}

 void Update()
 {
     startFlash();
     if(isFlashing)
         mat.color = new Vector4 (color.r,color.g,color.b,($$anonymous$$athf.Sin (Time.time*8+1)/2));
 }
 
 public IEnumerator startFlash (){
     isFlashing = true;
     yield return new WaitForSeconds(2);
     isFlashing = false;
 }

}

avatar image llnk7 · Aug 29, 2014 at 05:33 AM 0
Share

Hello again!

Well I think it is because you never change the value of isFlashing. I down know but I guess it is 'cause you have to call it like I said with StartCoroutine() so I would try this:

 public class JmpFlasher : $$anonymous$$onoBehaviour {
 
 $$anonymous$$aterial mat;
 public Color color;
 public bool isFlashing;
 // Use this for initialization
 void Start () {
     isFlashing = false;
     mat = new $$anonymous$$aterial (Shader.Find("Transparent/Diffuse"));
     mat.color = new Vector4 (color.r,color.g,color.b,1);
     renderer.material = mat;
     StartCoroutine(startFlash());
 }
  
 void Update()
 {
     if(isFlashing)
         mat.color = new Vector4 (color.r,color.g,color.b,($$anonymous$$athf.Sin (Time.time*8+1)/2));
 }
  
 public IEnumerator startFlash (){
     isFlashing = true;
     yield return new WaitForSeconds(2.0f);
     isFlashing = false;
 }
 }

And I think that would be all... I hope this works! good luck!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to make a sphere/ball blinking 4 Answers

Problem with shaders and textures: drop FPS and blinks 2 Answers

Network View - Player is blinking, and visible only partially during movement. 0 Answers

How can you make an enemy follow you only when look away or blink? 1 Answer

Simple Blinking when mouse click script 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