Search Unity

Creating a Flashing Color Script

Discussion in 'Scripting' started by iWoundPwn, Dec 26, 2013.

  1. iWoundPwn

    iWoundPwn

    Joined:
    Feb 16, 2013
    Posts:
    212
    I want to create a christmas lighting effect where the colors flash different colors I was thinking something like this yet I don't quite know...can anyone help?
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FlashColorScript : MonoBehaviour
    5. {
    6.     public GUIText myText;
    7.     public Color myTextColor;
    8.  
    9.     void Update ()
    10.     {
    11.         myText.material.color = myTextColor;
    12.         StartCoroutine (Yield ());
    13.     }
    14.  
    15.     IEnumerator Yield()
    16.     {
    17.         yield return new WaitForSeconds (1);
    18.     }
    19. }
     
  2. iWoundPwn

    iWoundPwn

    Joined:
    Feb 16, 2013
    Posts:
    212
    Here is what it looks like done but when I assign the GUItext variable to the text it disappears :/
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FlashColorScript : MonoBehaviour
    5. {
    6.     public GUIText myText;
    7.     public Color myTextColor1;
    8.     public Color myTextColor2;
    9.  
    10.     void Update ()
    11.     {
    12.         myText.material.color = myTextColor1;
    13.         StartCoroutine (Yield ());
    14.         myText.material.color = myTextColor2;
    15.  
    16.     }
    17.  
    18.     IEnumerator Yield()
    19.     {
    20.         yield return new WaitForSeconds (1);
    21.     }
    22. }