I want to change the Computer Input to Mobile Touch Input, if I press Space Button it shoots but how do I change this [Code] to Touch Input ?
I want it to have it into void OnTouchDown() but what do I have to put into the if(...) in the ShootingScript if I want to have it for Mobile to work ?
Here is my Shooting Script and my Player Controller Script
ShootingScript:
public GameObject shootingBullets;
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Space))
{
Instantiate(shootingBullets, transform.position, Quaternion.identity);
}
}
PlayerControllerScript:
public float jumpHeight;
void OnTouchDown()
{
if (GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>().velocity.y < 0.001f && GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>().velocity.y > -0.001f)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpHeight);
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.UpArrow) && GetComponent<Rigidbody2D>().velocity.y < 0.001f && GetComponent<Rigidbody2D>().velocity.y > -0.001f)
{
GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpHeight);
}
if (Input.GetKeyDown (KeyCode.DownArrow))
{
GetComponent<Rigidbody2D>().AddForce(-Vector2.up * jumpHeight);
}
}