Help in code for Key.

Hi. J’m from poland, so I use translator. Proszę nie patrzeć na błędy. J finished the course JavaScript, but but it was short. I have a problem with the script for the keys. So looks like the script in which you press one begins to execute the code.

function Update () {
     if (Input.GetKeyDown("1")){
     ; //code to do
}
}

I want that when you click one code began to perform, but the next stop. How does the script look like then?

Welcome to the unity3d forums!

unfortunately i don’t know the answer to your question, i am a begginer in scripting.

it would be easyer for others to read your script if you place the script inside in future posts.

You are on the right track. If you check out this documentation, it will give you all the answers you need to know:

Hope that helps.

But i can find script, which start excute the code when I click 1, a stop, when i click 1 again.

Oh, you want to toggle the script on or off when 1 is pressed?

-Script is off
-player presses 1
-script turns on
-player presses 1
-script turns off
-repeat…

if thats the case, you will need another variable, probably a boolean, to turn ‘on’ and ‘off’ when the player presses 1. Then, instead of turning the script on and off by the player input, you base it off that on/off variable.

Thanks. A what about this:
-Script is on, excute the code 1
-I press 1
-Script is still on, but excute the code 2
?