Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why can´t I Jump???

Discussion in 'Scripting' started by WilderMO, Aug 30, 2020.

  1. WilderMO

    WilderMO

    Joined:
    Aug 3, 2020
    Posts:
    1
    Hello I just Startet Learning C# and Working on my First Game.
    Its an Platformer Game.
    Everything Works just the Jump Skript wont Work. Unity Says ist " Assets\Skript\Movement.cs(48,34): error CS1002:;expected" I dont know what to do. Pls Help me.
    My Code is:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movement : MonoBehaviour
    6. {
    7.     public float Speed = 100f;
    8.     public float JumpForce;
    9.  
    10.     bool isJumping;
    11.     Rigidbody2D rb;
    12.  
    13.     void Update()
    14.     {
    15.         // Moves the Player\\
    16.         transform.Translate(Input.GetAxisRaw("Horizontal")* Speed *Time.deltaTime, 0f, 0f);
    17.         // Player Jumps\\
    18.         void Jump()
    19.         {
    20.             if(Input.GetKeyDown (KeyCode.Space) && !isJumping)
    21.             {
    22.                 isJumping = true;
    23.  
    24.                 rb.AddForce(new Vector2(rb.velocity.x, JumpForce));
    25.             }
    26.         }
    27.         Jump();
    28.  
    29.         //Flip Player\\
    30.         Vector3 characterScale = transform.localScale;
    31.         if (Input.GetAxis("Horizontal") < 0)
    32.         {
    33.             characterScale.x = -51;
    34.         }
    35.         if (Input.GetAxis("Horizontal") > 0)
    36.         {
    37.             characterScale.x = 51;
    38.         }
    39.         transform.localScale = characterScale;
    40.     }
    41.  
    42.     void OnCollisionEnter2D(Collision2D other)
    43.     {
    44.         if (other.gameObject.CompareTag("Ground"))
    45.         {
    46.             isJumping = false;
    47.  
    48.             rb.velocity = Vector2.0;
    49.         }
    50.     }
    51. }
    52.  
    Thanks 4 Help
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Actually, everything ISN'T working: You have a syntax error in the code so it will not compile, and thus nothing runs.

    The error message was provided with a line number but you neglected to include it, as well as reference it in the posted code, so it is impossible to help you.

    Go back to the error, find the offending line of code, and note which line that is in the above code.

    How to report problems productively in the Unity3D forums:

    http://plbm.com/?p=220

    Help us to help you.
     
    WilderMO likes this.
  3. GameAdvanced

    GameAdvanced

    Joined:
    Aug 30, 2020
    Posts:
    4
    If syntax is correct look at the project settings and see anything wrong in gravity
     
  4. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    343
    Line 48, no such thing as
    Code (CSharp):
    1. rb.velocity = Vector2.0;
    You probably wanted
    Code (CSharp):
    1. rb.velocity = Vector2.zero;