hello guys iam begginer in unity this is my code for my 2d ball game i want to make for mobile to move with there gui buttons left and right and jump button any idea how to do it ? every one is saying to me to start simple so iam making simplest game ball to move and jump its working in pc now i wanted to make it for mobile…
here is my code can someone tell me how to make it for mobile?
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool grounded;
private bool doubleJumped;
private Animator anim;
void Start () {
anim = GetComponent<Animator> ();
}
void FixedUpdate()
{
grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
}
void Update ()
{
if (grounded)
doubleJumped = false;
if (Input.GetKeyDown (KeyCode.Space) && grounded)
{
//GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
Jump ();
}
if (Input.GetKeyDown (KeyCode.Space) && !doubleJumped && !grounded)
{
//GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
Jump ();
doubleJumped = true;
}
if(Input.GetKey (KeyCode.D))
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if(Input.GetKey (KeyCode.A))
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
anim.SetFloat ("Speed", Mathf.Abs(GetComponent<Rigidbody2D> ().velocity.x));
}
public void Jump()
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
}