Search Unity

Please help me an newbie out!!

Discussion in 'Scripting' started by Hades II, Nov 25, 2014.

  1. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    I am developing an 2D game for android. I need to know if using the pace bar to make to player jump will work on the device as if to tap the screen.
    here is the code
    using UnityEngine;

    public class Player : MonoBehaviour
    {
    // The force which is added when the player jumps
    // This can be changed in the Inspector window
    public Vector2 jumpForce = new Vector2(0, 300);

    // Update is called once per frame
    void Update ()
    {
    // Jump
    if (Input.GetKeyUp("space"))
    {
    rigidbody2D.velocity = Vector2.zero;
    rigidbody2D.AddForce(jumpForce);
    }
    }
    }




    Thanks any help is welcome
     
  2. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    Have you tried testing it on a device?

    I don't think so. I know GetMouseButtonDown() does.
     
  3. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    Im having problems with testing on my android device...it keeps closing on me without showing anything
    not sure why it just shows an blank screen
     
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Probably not. Use mouse buttons instead or do an OR with touches.
     
  5. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    Will the mouse button work the same as if i tap the screen to make the object move
     
  6. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    use this:

    Code (csharp):
    1.  
    2. void Update()
    3. {
    4.     if (Input.GetMouseButtonDown(0))
    5.     {
    6.         //jumping!
    7.     }
    8. }
    9.  
     
  7. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    Sluice thank you a lot i cant thank you enough haha
     
  8. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    but im still having problems testing it on my device