Scaling an object based on the distance between it and the mouse cursor

If you want Scale an object (ex: sprite) based on the distance between it and the mouse position in your 2D game

this unity tutorial will help you

Video Tutorial

Ask or Request for anything you want in the comments below 😀

using UnityEngine;

public class ScaleObject : MonoBehaviour {

	public float maxdistance = 10;
	float temp;

	void Start () 
	{
		temp = transform.localScale.y;
	}
	
	void Update ()
    {
        Vector3 p = Input.mousePosition;
        Vector3 pos = Camera.main.ScreenToWorldPoint(p);
        Debug.Log(Vector2.Distance(transform.position, pos));	
        float distance = Vector2.Distance(transform.position, pos);

        if (distance < maxdistance)
        {
            float s = maxdistance - distance;
			transform.localScale = new Vector3(transform.localScale.x, temp-(s * temp/maxdistance), transform.localScale.z);
        }

    }

}

FOR MORE