- Home /
Question about letting the user choose 2 buttons and highlight them
Hello
i have written a script to let the user select buttons
but i want the script make him only choose 2 buttons and highlight them, so if he chose 3rd button the 1st button will not be highlighted
this is my code for the buttons and toggling them on and off (if you have any ideas tell me please, and what if i want alot of buttons should i keep using the if elseif?)
public GameObject Green;
public GameObject Purple;
private int a=0;
private int b=0;
private SpriteRenderer spriteRenderer;
private SpriteRenderer spriteRenderer3;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer3 = GetComponent<SpriteRenderer>();
}
void OnMouseDown()
{
if (gameObject.name == "GreenB" && a==0)
{
spriteRenderer.sprite = highlighted;
a=1;
}
else if (gameObject.name == "GreenB" && a==1)
{
spriteRenderer3.sprite = gray;
a=0;
}
if (gameObject.name == "PurpleB" && b==0)
{
spriteRenderer.sprite = highlighted;
b=1;
}
else if (gameObject.name == "PurpleB" && b==1)
{
spriteRenderer3.sprite = gray;
b=0;
}
Comment
Your answer
