Rotation On x-y Axis

Hii everyone…

I want to rotate my object based on touch input. For example we have rotation of object in preview of gameobject in Unity editor.

When we select this object we are able to see whole object view by rotating it. I want same feature on touch.

I tried some code which is here :

function Update()
 { 
 		var target : GameObject = GameObject.FindGameObjectWithTag("Target");
 		if(target)
 		{
  	 		if (Input.touchCount > 0) 
	     	{       
	             var theTouch : Touch = Input.GetTouch(0);        //    Cache Touch (0)
	             
	             var ray = Camera.main.ScreenPointToRay(theTouch.position);
	           
	                 if(Input.touchCount == 1)
	                 {
	                     
	                      if (theTouch.phase == TouchPhase.Began) 
	                      {
	                          wasRotating = false;    
	                      }        
	                      
	                      if (theTouch.phase == TouchPhase.Moved) 
	                      {
	                           if(Input.GetTouch(0).deltaPosition.x > 0)
	                           {
	                           	     target.transform.Rotate( Vector3(0, -theTouch.deltaPosition.x * rotationRate,0) , Space.Self);
	                           }
	                           else if(Input.GetTouch(0).deltaPosition.y > 0)
	                           {
	                           		target.transform.Rotate(Vector3(theTouch.deltaPosition.y * rotationRate, 0,0) , Space.Self);
	                           }

	                          wasRotating = true;
	                      } 
	                 
	     			 }
	 		 }
  	 	}
 }

This code is not working as expected. If anyone knows about it then please help me. Thanks…

Without more info on how it behaves I can only give this suggestion

try this code

if (theTouch.phase == TouchPhase.Moved) 
{
	target.transform.Rotate( Vector3(theTouch.deltaPosition.y * rotationRate, -theTouch.deltaPosition.x * rotationRate,0) , Space.Self);

	wasRotating = true;
}