I want to rotate my ball left or right.

here is the code.
private Vector2 lastTouchPos;
[HideInInspector]
public bool nonstop;
private Rigidbody rigidbody;
private Vector3 startpos;
private Vector3 endpos;
private Vector3 final;
Vector2 touchDeltaPosition;
Vector2 touchPosition;
public GameObject scorePanel;
private OpenSocreScript openSocreScript;
public GameObject ball;

private void Start()
{
    nonstop = true;
    rigidbody = GetComponent<Rigidbody>();
    openSocreScript = scorePanel.GetComponent<OpenSocreScript>();
}

private void FixedUpdate()
{
    // transform.position = new Vector3(Mathf.Clamp(transform.position.x, -2.4f, 2.4f), transform.position.y, transform.position.z);
    if (Input.touchCount > 0 && nonstop)
    {
        if (Input.GetTouch(0).phase == TouchPhase.Began)
        {                
            final = Vector3.zero;
            touchDeltaPosition = Input.GetTouch(0).position;
            startpos = new Vector3(touchDeltaPosition.x, 0, touchDeltaPosition.y);
        }

        if (Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            Vector2 v = Input.GetTouch(0).deltaPosition;
            //  lastTouchPos = Input.GetTouch(0).position;
          //  transform.Translate(new Vector3(v.x * Time.fixedDeltaTime * 2, 0, 0) , Space.World);
            rigidbody.velocity = new Vector3(v.x * Time.fixedDeltaTime*2, 0, 0);
            
        

    }

        if (Input.GetTouch(0).phase == TouchPhase.Ended)
        {               
            rigidbody.velocity = Vector3.zero;
            rigidbody.angularVelocity = Vector3.zero;
            touchPosition = Input.GetTouch(0).position;
            endpos = new Vector3(touchPosition.x, 0, touchPosition.y);
            final = endpos - startpos;
            Debug.Log("touch offset............" + final.normalized);
            if (touchPosition.y - touchDeltaPosition.y > 200f)
            {
              //  openSocreScript.OpenMenu();
                rigidbody.AddForce(final.normalized * 10f * Time.fixedDeltaTime*100, ForceMode.Impulse);
                nonstop = false;
                AnimateBall();
            }
        }
    }
}

public void AnimateBall()
{
    if (ball != null)
    {
        Animator animator = ball.GetComponent<Animator>();
        if (animator != null)
        {
             bool isOpen = animator.GetBool("open");
             animator.SetBool("open", !isOpen);
        }
    }
}

public void Reset(object _ball)
{
    AnimateBall();
    gameObject.transform.position = new Vector3(0f, 0.4451873f, -7.29f);
    gameObject.transform.rotation = Quaternion.Euler(new Vector3 (0,0,0));
    gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
    gameObject.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
}

As highpockets points out in the comments, this is not really a problem or an error. There is no explanation about what the problem is. Posting code this way makes it seem like you just want other people to do the work for you. Anyway, if i got this right, the deltaPosition only gives a magnitude and not a direction. If you want to rotate the ball according to if the player swiped left or right, you need to check if the position has moved left or right.


As an example, lets say the player started the touch at 0,0. The player moves left and the position is now -2,0. You can check this in an if-statement:

if(startPosition.x > endPosition.x)
{
    //player has swiped left
}
else if(startPosition.x < endPosition.x)
{
    //player has swiped right
}
else
{
    //the player has swiped, but not left or right, so up or down
}