[Unsolve]How to Toggle Gameobject between black and white color by using OnMouseDown method?
I try using OnMouseDown method but it seems not working properly, but instead when I remove the if statement in the code, it works but this way I cannot toggle.
void Start ()
{
print (shovel);
thistool = GetComponent<SpriteRenderer> ();
print (thistool.color);
}
void Update () {
}
void OnMouseDown ()
{
if (thistool.color == Color.black) {
thistool.color = Color.white;
}
if (thistool.color == Color.white) {
thistool.color = Color.black;
}
}
Answer by Dragate · Oct 20, 2017 at 11:42 AM
What your code does: If it is black (let's assume it is), make it white. if it is white (which is true cause you just made it), make it black. So, from black you went to black! Try this:
if (thistool.color == Color.black) {
thistool.color = Color.white;
} else if (thistool.color == Color.white) {
thistool.color = Color.black;
}
your solution is also not working. I think may be I have to use another method.
Could you provide information on what is happening?
nothing happens when I click on it. When I remove the if statement, it somehow worked, but it is not how I want it. I want it to switch between black and white when I click on it.
void On$$anonymous$$ouseDown ()
{
thistool.color = Color.white;
}
Your answer
Follow this Question
Related Questions
How to change the color of my text object? 1 Answer
Mouse-Keyboard Not Working - New User 1 Answer
Needing help with 3rd person mouse camera 1 Answer
Get coordinates of mouse-click on plane 1 Answer
Color.Lerp over HP 1 Answer