Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Change color of text mesh but line by line?

Discussion in 'Scripting' started by San_Holo, Nov 30, 2014.

  1. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    Hi,

    Do you know what I mean? like an old Atari computer demo... the code below will change my text meshes color at random, but I wondered if I couldn't apply a color to each line of the character set instead and perhaps rotate through them, would be a nice effect if it can be done, if you could advise me further if possible, thanks

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RandomColors : MonoBehaviour
    5. {
    6.         public GameObject Object;
    7.         Color[] colors = new Color[8];
    8.  
    9.         void Start ()
    10.         {
    11.                 colors [0] = Color.black;
    12.                 colors [1] = Color.white;
    13.                 colors [2] = Color.red;
    14.                 colors [3] = Color.cyan;
    15.                 colors [4] = Color.magenta;
    16.                 colors [5] = Color.green;
    17.                 colors [6] = Color.blue;
    18.                 colors [7] = Color.yellow;
    19.         }
    20.  
    21.         void FixedUpdate ()
    22.         {
    23.                 gameObject.renderer.material.color = colors [Random.Range (0, colors.Length)];
    24.         }
    25. }