- Home /
 
 
               Question by 
               Rise2 · Jun 18, 2018 at 08:18 PM · 
                c#unity 2dcolorspriterenderercolor change  
              
 
              SpriteRender.color not changing the color
So I have this ghost power up that should make the main character's SpriteRenderer color darker to make the main character like a ghost. This is my code and thank you in advance:
 public SpriteRenderer head;
 public SpriteRenderer tail;
 private Color snakeColor;
 // goes to gray, smaller the float is
 public float rgb = 255.0f;
 public collision collision;
 public float countdown = 10.0f;
 public bool bob = false;
 public bool transparenter = false;
 void Update()
 {
     if (collision.ghost == true || bob == true)
     {
         Ghost();
         countdown -= Time.deltaTime;
     }
     if (countdown <= 0.0f)
     {
         collision.ghost = false;
         bob = false;
         countdown = 10.0f;
         rgb = 255.0f;
     }
 }
 public void Ghost()
 {
     if (rgb > 200.0f)
     {
         rgb -= 1.0f;
     }
     snakeColor = new Color(rgb, rgb, rgb);
     head.color = snakeColor;
     tail.color = snakeColor;
 }
 
               }
               Comment
              
 
               
              Answer by SlowCircuit · Jun 18, 2018 at 08:56 PM
Color values are between 0 and 1, not 0 and 255. So do this instead:
 snakeColor = new Color(rgb / 255f, rgb / 255f, rgb / 255f);
 
              Your answer
 
             Follow this Question
Related Questions
Make the cube have the same color as the background every 3 seconds 0 Answers
Finding all sprite renderers in the scene and tell them to change color 1 Answer
Array of colors not working, all sprites turn white. 1 Answer
How to create shared color channels 1 Answer
How to change the color of an image every two seconds 1 Answer