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

Jump and Forward same time

Discussion in '2D' started by Zozzancs, Jun 20, 2014.

  1. Zozzancs

    Zozzancs

    Joined:
    Jun 14, 2014
    Posts:
    12
    Hey guys i wanna use the touch screen and i can't figure out how to press the jump button and the left or the right button at the same time

    so i wanna press the left arrow and the jump at the same time but i cant figure out how... pls help me


    Code (JavaScript):
    1. var speed : float = 10; //Variables
    2.  
    3. var jump :float = 0; //Check if the player can jump
    4. var jumpspeed : float = 15; //Check how high the player can jump
    5. var jumptimer :float = 0; //Make the player can jump again using this timer
    6.  
    7.  
    8. function Start () {
    9.  
    10. }
    11.  
    12. function Update () {
    13.  
    14. if (jump == 1) {
    15. jumptimer = jumptimer +1;
    16. if (jumptimer >= 50) {
    17. jumptimer = 0;
    18. jump = 0;
    19. }
    20. }
    21.  
    22. if (CFInput.GetButton ("Arrow"))
    23. {
    24. transform.Translate(Vector3(-speed,0,0) * Time.deltaTime);
    25. }
    26.  
    27. if (CFInput.GetButton ("Arrow2"))
    28. {
    29. transform.Translate(Vector3(speed,0,0) * Time.deltaTime);
    30. }
    31.  
    32. // jump whenever the user hits the jump button
    33. if (CFInput.GetButtonDown ("Jump"))
    34. {
    35. if (jump == 0) {
    36. rigidbody.velocity.y = jumpspeed;
    37. jump = 1;
    38. }
    39. }
    40.  
    41. }


    i using Controll Freak plugin ( the touch screen is working i have only problem with pressing left or right and the jump at the same time:)
     
  2. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    Code (JavaScript):
    1. public var jumpButton : GameObject;
    2. private var activateJump : boolean = false;
    3. public var interactButton : GameObject;
    4. private var activateGrab : boolean = false;
    5. public var rightButton : GameObject;
    6. private var activateRight : boolean = false;
    7. public var leftButton : GameObject;
    8. private var activateLeft : boolean = false;
    9. public var upButton : GameObject;
    10. private var activateUp : boolean = false;
    11. public var downButton : GameObject;
    12. private var activateDown : boolean = false;
    13.  
    14. function Update ()
    15. {
    16.     activateRight = false;
    17.     activateLeft = false;
    18.     activateUp = false;
    19.     activateDown = false;
    20.     activateJump = false;
    21.     activateGrab = false;
    22.  
    23.     for (var touch : Touch in Input.touches)
    24.     {
    25.         if (jumpButton.guiTexture.HitTest (touch.position) && touch.phase != (TouchPhase.Ended) && !jumping)
    26.           {
    27.               activateJump = true;
    28.         }
    29.         if (interactButton.guiTexture.HitTest (touch.position) && touch.phase == (TouchPhase.Ended))
    30.           {
    31.               activateGrab = true;
    32.         }
    33.         if (rightButton.guiTexture.HitTest (touch.position) && touch.phase != (TouchPhase.Ended))
    34.           {
    35.               activateRight = true;
    36.         }
    37.         if (leftButton.guiTexture.HitTest (touch.position) && touch.phase != (TouchPhase.Ended))
    38.           {
    39.               activateLeft = true;
    40.         }
    41.         if (upButton.guiTexture.HitTest (touch.position) && touch.phase != (TouchPhase.Ended))
    42.           {
    43.               activateUp = true;
    44.         }
    45.         if (downButton.guiTexture.HitTest (touch.position) && touch.phase != (TouchPhase.Ended))
    46.           {
    47.               activateDown = true;
    48.         }
    49.     }
    50.         <Your movement code based on the booleans>
    51. }
     
  3. Zozzancs

    Zozzancs

    Joined:
    Jun 14, 2014
    Posts:
    12
    ty but not working... error: jumping
     
  4. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    huh? that is code straight out of my game lol. It isnt complete however. i have skype if you need better instructions, that is simpley used to collect multiple touches at the same time.
     
  5. Zozzancs

    Zozzancs

    Joined:
    Jun 14, 2014
    Posts:
    12
    can you give me your skype adress ? :)
     
  6. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    kilrath81