Camera touch control script

I need camera controll by touchscreen like in angry bird and many other 2d games(it look like scrolling).

A rough guide to moving the camera based on touch.

This is in C# and moves the camera on the Y axis only. It’s pretty rough and hasn’t been tested.

If you wanted to fiddle, you could add momentum (so the camera continues to move after your finger raises) and a scaling factor to the deltaPosition so you can turn sensitivity up or down.

class TouchCameraMover
{
   // The ID of the touch that began the scroll.
   int ScrollTouchID = -1;
   // The position of that initial touch
   Vector2 ScrollTouchOrigin;

   void Update()
   {
       foreach(Touch T in Input.touches)
       {
          //Note down the touch ID and position when the touch begins...
          if (T.phase == TouchPhase.Began)
	      {									
		if (ScrollTouch == -1)
		{
		   ScrollTouchID = T.fingerId;	
		   ScrollTouchOrigin = T.position;	
            }
          }
          //Forget it when the touch ends
          if ((T.phase == TouchPhase.Ended) || (T.phase == TouchPhase.Canceled))
	      {									
  	        ScrollTouchID = -1;	
          }
          if (T.phase == TouchPhase.Moved)
	      {
                //If the finger has moved and it's the finger that started the touch, move the camera along the Y axis.
		    if (T.fingerId == ScrollTouchID)
		    {
                     Vector3 CameraPos = Camera.main.transform;
                     Camera.main.transform = new Vector3(CameraPos.x,CameraPos.y + T.deltaPosition.y,CameraPos.z);
                }
          }
       }
   }
}