2D get touch input

Hello fellow unity developers, I am stuck with a little problem here, the problem is that I don’t seem to get any touch input, the purpose of this script is to detect of the position of the player is higher/lower on the x/y axes and then follow an instruction.
Determining the player position does work but any touch input doesn’t seem to get picked up, Thanks in advance!

This is the script:

function PlayerMove() {

var pos = Camera.main.ScreenToWorldPoint(Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));
var playerposx = GameObject.Find("player2").transform.position.x;
var playerposy = GameObject.Find("player2").transform.position.y;

//Debug.Log (playerposx); //display playerpos x in console
//Debug.Log (playerposy); //display playerpos z in console

    if (pos.x < playerposx){ // move to the left
     	
     	rigidbody2D.velocity.x = speed * -1;
     	
  	  }
     
   	 else {
   	  
     	Debug.Log ("Move to the left doesn't work");
     		
   		}
	}

i believe the issue might be that your defining the variable but not actually initiating anything to determine if you have hit the screen i could be wrong but Try this to check

// to set the pos variable when we hit the screen.
if(Input.GetTouch(0)) { 
var pos = Camera.main.ScreenToWorldPoint(Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));
Debug.Log("pos.ToString()); // this will tell u if the variable
is atleast recieving its correct value
}

hope this helps, if it doesn’t let me know and i’ll re-assess.