void RunButtons(RaycastHit2D hit) { foreach (Button b in buttons) { b.isClicked = false; if (hit && hit.transform.gameObject == b.gameObject && CInput.MouseClick(0)) { b.isClicked = true; } if (hit && hit.transform.gameObject == b.gameObject && Input.GetMouseButton(0) && b.clicked) { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.clicked; } else if (b.gameObject) { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.normal; } } foreach (SwitchButton b in switchButtons) { b.isClicked = false; if (hit && hit.transform.gameObject == b.gameObject && CInput.MouseClick(0)) { b.isClicked = true; b.on = !b.on; } if (hit && hit.transform.gameObject == b.gameObject && Input.GetMouseButton(0) && b.clicked) { if (b.on) { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.clicked; } else { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.switchClicked; } } else if (b.gameObject) { if (b.on) { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.normal; } else { b.gameObject.GetComponent <SpriteRenderer>().sprite = b.switchNormal; } } } }