Moving object which side we touch the ipad

Hello Every One,

I am new for ios development so i actually try to do moving the object from right left side. My object should move right side when i touch the right side of the screen and move left side when i touch the left side of the screen. But i did not get the output for this till now,

Please help me to do this.

Here is my code:

void Update () {
		
		if(Input.touchCount > 0  Screen.width/3 < 0){
		
			transform.Translate(Vector3.right * Time.deltaTime * 10);
			
		}
		
	
		
		else if(Input.touchCount > 0  Screen.width/3 > 0 )
		{
			transform.Translate(Vector3.left * Time.deltaTime * 10);
			
		}
	
	
	}

First of all, you could probably just check for Input.GetMouseButtonDown(0). It works with mouse and also responses to single touch. Second of all, I didn’t quite figure out your logic about the position checking. Perhaps some kind of misunderstanding? You’re literally checking wether the screen width divided by 3 is lesser or greater than zero. That is going to be greater than zero all the time. So you probably need to use the mouse position (Input.mousePosition) and check where it is. Something like this:

    void Update () {
           
            if(Input.GetMouseButtonDown(0)  Input.mousePosition.x  > Screen.width * 0.66){
           
                transform.Translate(Vector3.right * Time.deltaTime * 10);
               
            }
           
       
           
            else if(Input.GetMouseButtonDown(0)  Input.mousePosition.x < Screen.width * 0.33))
            {
                transform.Translate(Vector3.left * Time.deltaTime * 10);
               
            }
       
       
        }

I didn’t test this, but you should get the idea. About those Translates I can’t say anything, I’ve done my movements solely with iTween.

EDIT: Updated Input.mousePosition to Input.mousePosition.x, slipped my mind.

ok i try this…

Forgot to put .x after Input.mousePosition, now fixed.