- Home /
 
               Question by 
               Subliminalman · Feb 04, 2014 at 07:56 PM · 
                colorruntimesprite renderer  
              
 
              Sprite not updating color.
Hey all,
I'm trying to set a sprite's color at runtime. I believe my code is correct but it is not currently working. The Debug statement returns the values I expect but the sprite is not updating. The script is attached to the sprite itself.
 using UnityEngine;
 using System.Collections;
 
 public class PuzzleBackground : MonoBehaviour {
     public SpriteRenderer spriteRenderer;
     Color [] colors = {new Color(54,196,152), new Color(114,213,127), new Color(219,128,183), 
                        new Color(127,201,255), new Color(237,237,128), new Color(166,153,222), 
                        new Color(242,143,86), new Color(103,208,213), new Color(51,167,179)};
     // Use this for initialization
     void Start () {
         spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
         RandomColor ();
     }
 
     void Update(){
         if(Input.GetKey(KeyCode.Space)){
             RandomColor();
         }
     }
 
     public void RandomColor(){
         spriteRenderer.color = colors[Random.Range (0, colors.Length)];
         Debug.Log (spriteRenderer.color);
     }
 }
Any ideas?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Eric5h5 · Feb 04, 2014 at 08:29 PM
Color uses floats in the range of 0.0 to 1.0. All the colors you have will be the same (namely, white).
lol spent the last 20$$anonymous$$ trying to figure out what is going on. Thank you Eric.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                