Input.GetKeyDown running twice

I am trying to accept, calculate, and display numerical input. The problem I’m having is that the code runs twice. Here is my code:

private var daysResting: int = 0;

if(Input.GetKeyDown (KeyCode.Alpha1) || Input.GetKeyDown (KeyCode.Keypad1))
     {
          daysResting = (daysResting * 10) + 1;
     }

this code should give me 1 and then 11, but instead it displays 11 the first time you hit “1”.

Hi Everybody! The reason is so simple that it is the reason why it is hard to realize. There are two object what hold the same script, this is the reason why run it twice (or more). This is also the reason why not work in this case to check is your code running or not.

Make sure that you don’t put your input testing in the OnGUI(). Put it in the Update() method.
I had the following code in the OnGui(). I had to place the second test as I was receiving duplicate events. :frowning:
By moving the code to Update() the duplicate GetKeyDown() stopped occurring.

I hope this helps someone.

if (Input.GetKeyDown (KeyCode.Escape))
{
   if (!( GameState == (int)state.aborting))
   { 
	PreviousGameState = GameState;
	GameState = (int)state.aborting;
    }
}

not sure what the problem you are having but i just ran the script and it added it perfect are you adding a day to daysRested somewhere else in the code before that function runs? try running the code by its self on a script else where you have to be adding a day somehow. try this and see here is the code i used to test it`
#pragma strict

var daysResting : int = 0;

function Start () {

}

function Update () {
if(Input.GetKeyDown(KeyCode.K) || Input.GetKeyDown(KeyCode.L)){

	daysResting = (daysResting * 10) + 1;
	print(daysResting);
}

}`

I’m having a similar problem, but I debugged and figured out that I only have one script of that type in my scene. I’m really confused as to what would be happening. I tried getkeydown and getbuttondown and neither worked. It’s all in the update function of the script on my player and I’m trying to make it jump once without creating two jump sounds. Any help would be appreciated!