Question by
RetroboltGames · Jun 04, 2019 at 08:20 PM ·
c#color change
How to change player's color more than once
When changing the player's color, I can only do it once. I'm trying to do it multiple times.
Thank you
private SpriteRenderer rend;
public Color colorToTurnTo = Color.white;
void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
rend = GetComponent<SpriteRenderer>();
rend.color = colorToTurnTo;
}
}
Comment
You will have to give more details about what you want to do exactly....
Your current code will change the color of the SpriteRenderer
to colorToTurnTo
when you press the L
key. If you press the key several times, the same color will be applied unless you change colorToTurnTo
in between.
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.L))
{
rend = GetComponent<SpriteRenderer>();
rend.color = colorToTurnTo;
colorToTurnTo = Random.ColorHSV( 0f, 1f, 1f, 1f, 0.5f, 1f ); // Will pick another random color
}
Hi,
What I'm really going for is when the player touches an object they will change color and be able to enter a certain area, then touch a different object to turn a different color to go elsewhere.
These colors will change each level.
Thank you