How to resize a game object with the mouse in unity 2d

Hi, here’s the problem, I need to make it so that when you right click on a sprite and then drag it to the side, the object changes size.
Really asking for help!!!

This is an interesting question so I thought it would be fun to code a solution for it.

Put this code on an empty GameObject in the hierarchy and it will scale any sprite that has the tag “Resizable”. If you don’t want to create an empty GameObject, you can put this code on the sprite itself, in which case you can remove the CompareTag test since it’s not needed in that case.

using UnityEngine;

public class ResizeWithDrag : MonoBehaviour
{
	Camera cam;
	bool resizing;
	GameObject targetSprite;
	Vector2 mouseStartPos;
	float startDistance;
	Vector3 startScale;

	void Start()
	{
		cam = Camera.main;
		resizing = false;
	}

	void Update()
    {
		if (Input.GetMouseButtonDown(1))
			GetTargetSprite();

		if (Input.GetMouseButtonUp(1))
			resizing = false;

		if (resizing)
			ResizeSprite();
    }

	void GetTargetSprite()
	{
		Vector2 worldPos = cam.ScreenToWorldPoint(Input.mousePosition);
		RaycastHit2D hit = Physics2D.Raycast(worldPos, Vector2.down);

		if (hit.collider != null)
		{
			if (hit.transform.CompareTag("Resizable"))
			{
				resizing = true;
				targetSprite = hit.collider.gameObject;
				mouseStartPos = worldPos;
				startDistance = Vector2.Distance(targetSprite.transform.position, worldPos);
				startScale = targetSprite.transform.localScale;
			}
		}
	}

	void ResizeSprite()
	{
		Vector2 newWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);

		float endDistance = Vector2.Distance(newWorldPos, targetSprite.transform.position);
		float scaleFactor = endDistance / startDistance;

		targetSprite.transform.localScale = startScale * scaleFactor;
	}
}

Let me know if you have any questions…