Search Unity

Need help with my jump script

Discussion in 'Scripting' started by Mcbeeff, Sep 23, 2014.

  1. Mcbeeff

    Mcbeeff

    Joined:
    Sep 14, 2014
    Posts:
    2
    varspeed : float = 5f;
    varjumpDelay : boolean;
    vardoubleJump : int = 0;
    functionupdate() {

    if(Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
    {
    Jump();
    }
    }

    functionJump()
    {
    if(doubleJump <= 1)
    {
    rigidbody.velocity.y = 175;
    jumpTimer();
    }
    }

    functionjumpTimer()
    {
    if(Input.GetKeyDown(KeyCode.Space))
    {
    doubleJump ++;
    }

    if (doublejump > 1)
    {

    doubleJump = 0;
    jumpDelay = true;
    transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
    jumpDelay = false;

    }
    }

    This is the jump script im using. It has compiling errors but im not sure what the issue is. Ive recently integrated transform.position += newVector3(speed * Time.deltaTime, 0.0f, 0.0f); into the script and am pretty sure my syntax is incorrect, if anyone could help me out i would appreciate it.
     
    Last edited: Sep 23, 2014
  2. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    Code (JavaScript):
    1. varspeed : float = 5f;
    2. varjumpDelay : boolean;
    3. vardoubleJump : int = 0;
    4.  
    5. function update()
    6. {
    7.     if(Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
    8.     {
    9.         Jump();
    10.     }
    11. }
    12.  
    13. function Jump()
    14. {
    15.     if(doubleJump <= 1)
    16.     {
    17.         rigidbody.velocity.y = 175;
    18.         jumpTimer();
    19.     }
    20. }
    21.  
    22. function jumpTimer()
    23. {
    24.     if(Input.GetKeyDown(KeyCode.Space))
    25.     {
    26.         doubleJump ++;
    27.     }
    28.  
    29.     if (doublejump > 1)
    30.     {
    31.         doubleJump = 0;
    32.         jumpDelay = true;
    33.         transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
    34.         jumpDelay = false;
    35.     }
    36. }
    Try to insert the code in a "code" block.
    Also, indentations are a must to make it readable.

    In the original code, there was no space between the word "function" and the name of the function, is that how it is in your code?
     
  3. Mcbeeff

    Mcbeeff

    Joined:
    Sep 14, 2014
    Posts:
    2
    Sorry haha yeah i just copy pasted i didnt realize there was a better way to post your code. Sorry about that lol.


    Code (JavaScript):
    1.  var jumpDelay : boolean;
    2. var doubleJump : int = 0;
    3. function update() {
    4.          if(Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
    5.          {
    6.                  Jump();
    7.          }
    8.      }
    9.    
    10.      function Jump()
    11.          {
    12.              if(doubleJump <= 1)
    13.              {
    14.                  rigidbody.velocity.y = 175;
    15.                  jumpTimer();
    16.              }
    17.          }
    18.        
    19.      function jumpTimer()
    20.      {
    21.          if(Input.GetKeyDown(KeyCode.Space))
    22.          {
    23.              doubleJump ++;
    24.          }
    25.        
    26.          if (doublejump > 1)
    27.          {
    28.        
    29.              doubleJump = 0;
    30.               jumpDelay = true;
    31.              transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
    32.              jumpDelay = false;
    33.            
    34.          }
    35.      }
    36.