need help badly

im practicing unity
can anyone show me example c# script of this.
i want when i press space 1 time the object will go all the way up
and while the object is going up and i press the space again the object will go all the way down.

hope some1 can help. thank you in advance

Ask smaller and more precise questions.

Try to solve one small part at a time.

Also, I would recommend that you try to find a better title for your topic/question, like “Moving an object over time from one position to another”

Topics in your question:

Moving objects every frame:

Reacting to player input:

States (is it on its way up or down):

Sounds like a Flappy Bird zig-zag to me. You should create a vector for movement, and change it every time you press a button. Something like:

    Vector3 direction = new Vector3(0,1,0);
    float speed = 0.01f;
    void Update(){
    	if (Input.GetKeyDown(KeyCode.Space)) {
    		direction.y *= -1;
    	transform.position += direction*speed;

This checks the space key and, if down, inverts the direction. Every update it moves the object by ‘speed’ distance. This doesn’t factor in screen refresh.

To be honest though, you really need to work through the tutorials to learn the basics of Unity. This is something that you should be able to work out for yourself from the documentation and online tutorials, because creating a game gets infinitely more complex than this! You’ll have to spend and effort learning the basics up to moderate ability as otherwise you’ll be asking questions like this all the time! :wink: