Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Program a cube to change color from White to vice-versa

Discussion in 'Scripting' started by LelandGMC, Dec 1, 2013.

  1. LelandGMC

    LelandGMC

    Joined:
    Apr 27, 2013
    Posts:
    15
    Hello i'm trying to learn how to program a cube to change colors from white to any color like black or blue to going back to the color.

    This is the code for the color cube:

    I'm supposed to use arrays in there too, I'm puzzled right now
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
  3. LelandGMC

    LelandGMC

    Joined:
    Apr 27, 2013
    Posts:
    15
    I kinda meant to program it in C#, i'm a beginner level programmer trying to code it from scratch.
     
  4. TheRealMacklebee

    TheRealMacklebee

    Joined:
    Nov 28, 2012
    Posts:
    16
    Based on the docs found here: Color.Lerp
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ColorLerp : MonoBehaviour
    5. {  
    6.     void Update()
    7.     {
    8.         renderer.material.color = Color.Lerp(Color.blue, Color.white, Mathf.PingPong(Time.time,2));
    9.     }
    10. }
    11.  
    Look through the documentation as there are several useful examples.
     
  5. LelandGMC

    LelandGMC

    Joined:
    Apr 27, 2013
    Posts:
    15
    It works, But i wanted to program in a way where it change colors back and forth when i click it

    I want to be able to Program it from:

    Change it from White to Black and vice-versa
    Use arrays to program it colors