Add 1 to an int when joystick is pulled

Hello,

I want to add +1 to my int when pulling right or left my joystick, but the value is added multiple times. I assume it is because i’m in the update behavior, but i have no idea how to do another way. Can you help me?

Here’s my code so far :

	public int MenuNumeroApt;


void Update()

	{


Debug.Log ("MenuNumeroApt : " + MenuNumeroApt);
LeftStickX = Input.GetAxis ("Horizontal");

if (LeftStickX == 1)
		{
			MenuNumeroApt=MenuNumeroApt+1;
		}
		else if (LeftStickX == -1)
		{
			MenuNumeroApt=MenuNumeroApt-1;
		}
}

thanks

bool canAddScore;

    public int MenuNumeroApt;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
    {

        if (Input.GetAxis("Horizontal") < 0.1f && Input.GetAxis("Horizontal") > -0.1f)
            canAddScore = true;

        if (Input.GetAxis("Horizontal") == 1 && canAddScore)
        {
            MenuNumeroApt = MenuNumeroApt + 1;
            canAddScore = false;
        }
        else if (Input.GetAxis("Horizontal") == -1 && canAddScore)
        {
            MenuNumeroApt = MenuNumeroApt - 1;
            canAddScore = false;
        }
	
	}
}

Try this hope it works for you… :slight_smile: