I need help in scripting for my new game which is clone of flappy bird

I made the game for windows it just perfect but now i want to make it for android
so what should i change in the script tto make it run for android ls explain in easy steps

  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);
          }
          
          // Die by being off screen
          Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
          if (screenPosition.y > Screen.height || screenPosition.y < 0)
          {
              Die();
          }
      }
      
      // Die by collision
      void OnCollisionEnter2D(Collision2D other)
      {
          Die();
      }
      
      void Die()
      {
          Application.LoadLevel(Application.loadedLevel);
      }
  }

2 Answers

2

Really you only need to change the input method. Add a canvas to your scene and add a button.make the button the full size of the canvas. Obviously you don’t want to see the button so either delete the image and text part or put a canvas group on there and set the Alpha to 0 (which is invisible).

Add a public void ScreenTapped() function to you script and put your space key stuff in there…

public void ScreenTapped()
{
    rigidbody2D.velocity = Vector2.zero;
    rigidbody2D.AddForce(jumpForce);
}

Select the button in the UI and look in the inspector, click + in the OnClick part of the button. Drag the item that holds you script onto the empty slot. Then from the drop down slect YourScriptName → ScreenTapped.

You need to alter the build settings as well File → Build Settings → Select Android and switch platform.

But can't it be little easier Pls explain in kinda like am a newbie to unity it's just like 1.5 months Pls

As you asked elsewhere where to drag the script to and where the drop down is. http://i.imgur.com/TMqfuiB.png Click + in the OnClick part and you should get a slot appear with a dropdown to the right of it.

bro and because of massive use of pc i lost my keyboard and mouse mom took them off and told me i need to devote hours to studies instead because i would earn nothing from what i m doing @mmmpies so still i had a spare mouse which is top secret so are all these stteps of onclick done with mouse only?

There's no point me doing a video tutorial, there are loads out there already... https://www.youtube.com/watch?v=TYzdhiRiKd0 That even shows how to pass variables into the function (you don't need that for this though). You're going to struggle massively without a keyboard though and your mom isn't wrong. Programming relies heavily on maths for example the more you know the easier it is.