I have multiple buttons in my scene, they all have the same script, but they have different public int values attached to them. I’m trying to click on 1 to get the first value, then click on a second to get the other value, then print them both to the Log. I understand why it isn’t working due to the constant checking of the Update method, but I’m not sure how I am meant to go about doing it. Here is the code I’ve currently got. Any hints on how to solve this issue are much appreciated.
Cheers
By putting an ‘else’ function in the update, then setting firstCircleSelected to false in the stateValues method, it seemed to fix it:
void Update(){
if (Input.GetMouseButtonDown (0) && (!firstCircleSelected)) {
hit = Physics2D.Raycast (new Vector2(Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y),Vector2.zero, Mathf.Infinity, circleLayerMask);
if (hit.collider != null){
Debug.Log ("First value found");
thisValue = hit.collider.gameObject.GetComponent<NumberValue>().value;
firstCircleSelected = true;
}
}
else
if (Input.GetMouseButtonDown (0) && (firstCircleSelected)) {
hit2 = Physics2D.Raycast (new Vector2(Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y),Vector2.zero, Mathf.Infinity, circleLayerMask);
if (hit2.collider != null){
Debug.Log ("Second value found");
thatValue = hit2.collider.gameObject.GetComponent<NumberValue>().value;
stateValues();
}
}
}