Sprite color changes in inspector but not in game
Hello.
I'm using this code to change the sprite's color when i collide with it.
SpriteRenderer renderer = GetComponent<SpriteRenderer>();
renderer.color = new Color(0, 1, 0, 1);
I have a debug message that tells me I've collided with the object and the color changes in the inspector but the sprite color stays the same. If i try to change the sprite color with the inspector while the game is running it also changes. This code worked fine with unity 5 but isn't with unity 5.5.0a6
Answer by LZakhar · Oct 12, 2016 at 09:19 PM
Meet this trouble with colors. For me works renderer.color = new Color32(byte r, byte g, byte b, byte a);
With Color, not Color32 I`ve got troubles too.
Answer by sid4 · Oct 08, 2016 at 06:15 PM
you need to add an oncollision function so when on collision the color will change can u post your code here?
I do have a collision function. It tells me I've collided with the object at which coordinates but it doesn't change the sprite color. Here's my code
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "Character") {
Level$$anonymous$$anager.check = gameObject.transform.position;
Debug.Log ("Checkpoint! :" + transform.position);
SpriteRenderer renderer = GetComponent<SpriteRenderer>();
renderer.color = new Color(0, 1, 0, 1);
}
}
}
I get the debug message when i collide and the color changes but only in the inspector. The color stays the same in the game.
Your answer
Follow this Question
Related Questions
Certain animation states not playing on mobile. Not sure if it's my code or a bug. 0 Answers
Tilemap doesn't showing on window?? unity 5.6.1f1 ,Tilemap not showing on the Window or as 2D Object 0 Answers
I'm lost. How to coordinate two sprite animations each other? 1 Answer
How to apply the same bind poses for a dynamically generated sprite? 0 Answers
How can make it so only 1 object of type “Ability” can be selected at once? 0 Answers