2D touch input

Hi
I would ccontrol my spaceship in 2d top down space shooter on my adnroid device I would add touch input but when I play the inputs don’t exist.

using UnityEngine;
using System.Collections;

[System.Serializable]
public class Boundary
{
    public float xMin, xMax, yMin, yMax; //Screen Boundary dimentions
}

public class Player_Script : MonoBehaviour
{
    //Public Var
    public float speed;             //Player Ship Speed
    public Boundary boundary;         //make an Object from Class Boundary
    public GameObject shot;            //Fire Prefab
    public Transform shotSpawn;        //Where the Fire Spawn
    public Transform shotSpawn1;        //Where the Fire Spawn1 extra
    public Transform shotSpawn2;        //Where the Fire Spawn2  extra
    public float fireRate = 0.5F;    //Fire Rate between Shots
    public GameObject Explosion;    //Explosion Prefab
    public GameObject restartDialog; //eND gAME
    public GameObject heart1;        // heart icon #1
    public GameObject heart2;        // heart icon #2
    public GameObject heart3;        // heart icon #3
   
    //Private Var
    private float nextFire = 0.0F;    //First fire & Next fire Time
    private bool  dead;
    private Shield shield;
    private int hits = 0;
    private Rigidbody2D rb;
    private Vector3 pos;                //Position
    void Start ()
    {
        restartDialog.SetActive(false);
        rb = GetComponent<Rigidbody2D>();
        shield = GameObject.Find("Shield").GetComponent<Shield>();
        HeartsCount(); // draw the right number of hearts on the screen
        hits = shield.lives; // make hits equal to shield.lives to start
       
    }

    void Update ()
    {
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
            int pos = Input.GetTouch(0).position;
            pos = Camera.main.ScreenToWorldPoint(pos);
            transform.position    = new Vector3(transform.position.x, 0, transform.position.z);
        //Excute When the Current Time is bigger than the nextFire time
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;                                 //Increment nextFire time with the current system time + fireRate
            Instantiate (shot , shotSpawn.position ,shotSpawn.rotation);     //Instantiate fire shot
            GetComponent<AudioSource>().Play ();                             //Play Fire sound
        }
        if(hits != shield.lives)
        {
            HeartsCount();
        }
    }
    }   
    // FixedUpdate is called one per specific time
    void FixedUpdate ()
    {
   
        //Lock the position in the screen by putting a boundaries
        GetComponent<Rigidbody2D>().position = new Vector2
            (
                Mathf.Clamp (GetComponent<Rigidbody2D>().position.x, boundary.xMin, boundary.xMax),  //X
                Mathf.Clamp (GetComponent<Rigidbody2D>().position.y, boundary.yMin, boundary.yMax)     //Y
                );
    }
   
    //Called when the Trigger entered
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Shield") // if we encounter a shield pickup...
        {
            shield.resetShield(); // reset shield durability to max
            HeartsCount(); // draw the right number of hearts on the screen
            // Debug.Log(gameObject.name + " got shields!");
            Destroy(other.gameObject); // and destroy the shield pickup object.
        //DoubleShot


            }
        //Excute if the object tag was equal to one of these
        if(other.tag == "Enemy" || other.tag == "Asteroid" || other.tag == "EnemyShot") // if we have no shields & we're hit by an enemy, bullet, or asteroid
        {
            // Debug.Log(gameObject.name + " has hit an " + other.gameObject.name);
            HeartsCount(); // draw the right number of hearts on the screen
            if (shield.lives == 0) // if we're out of shields, explode, self-destruct, and show the restart dialog.
            {
                // Debug.Log("Player has no shields left! Destroying player!");
                Instantiate (Explosion, transform.position , transform.rotation);     
                //Trigger That its a GameOver
                Destroy(gameObject);
                restartDialog.SetActive(true);
            }
        }
    }

    void HeartsCount()
    {
        hits = shield.lives;
        if(shield.lives == 3) // if we have full shields (3)...
        {
            heart3.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #3.
            heart2.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #2.
            heart1.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #1.
        }
        if(shield.lives == 2) // if shields are at 2...
        {
            heart3.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #3.
            heart2.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #2.
            heart1.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #1.
        }
        if(shield.lives == 1) // if shields are at 1...
        {
            heart3.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #3.
            heart2.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #2.
            heart1.gameObject.GetComponent<SpriteRenderer>().enabled = true; // turn on heart #1.
        }
        if(shield.lives == 0) // if shields are at 0...
        {
            heart3.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #3.
            heart2.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #2.
            heart1.gameObject.GetComponent<SpriteRenderer>().enabled = false; // turn off heart #1.
        }
    }
    void FireBullet(){
        GameObject Clone1;
        GameObject Clone2;

        Clone1 = (Instantiate(shot,shotSpawn1.position ,shotSpawn1.rotation)) as GameObject;
        Clone2 = (Instantiate(shot,shotSpawn2.position ,shotSpawn2.rotation)) as GameObject;
        Debug.Log ("Bullet is found");
    }
    public void RestartMenu()
    {
        Application.LoadLevel (Application.loadedLevelName);
    }
   
    public void ExitToMenu()
    {
        Application.LoadLevel ("Menu");
    }
   
}

It looks like you are using pos as several data types here. I’m no expert but you initially state pos as a Vector3 and then declare pos as an int for Input.GetTouch(0).position (returns Vector2 btw) and then calling it back as both a Vector2 and Vector3 when you try to declare pos in world coordinates. I mean if I am wrong by all means, bash me for it. But this just doesn’t look right haha.

Instead for lines 45 to 47, I’d change to

if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 screenPos = Input.GetTouch(0).position;
pos = Camera.main.ScreenToWorldPoint(screenPos);
//Continue with rest of code

Thanks for your reply but it still no get input when I touch the screen

I was reading through the forums came across someone having the issue. Is you unity client up to date?

yes why?

Thought it could’ve been the cause of a earlier editor. Honestly, i can’t give you a good reason to why it’s happening cause i am not familiar with touch devices and unity but i thought i would at least try since there were no replies. Try googling the problem and maybe someone has a solution, wish i could’ve been more of a help.

Perhaps try debug.log touchcount to see if it’s registering that and move along from there.

Edit: Just saw a forum post where they seemed to have solved it. [Solved] Input class no longer registers touches - Unity Engine - Unity Discussions