Trying to get Canvas child Panel to resize.

Basically what i am trying to do is write a script that can resize Ui element that are child of the canvas dynamically so the user can have control over the size and placement of them. Placement and moving them was easy, resizing them based on input how ever is giving me fits lol. I clearly am either not understanding how anchors work or i am just not taking the proper approach.

I’ve read the doc’s and tried a bunch of different tutorials and asset store scripts and i still couldn’t find
a “simple” working solution. Tyvm in advance for your time i do greatly appreciate it and if i could have slogged it out on my own i would have.

using UnityEngine;
using System.Collections;

public class ResizeElements : MonoBehaviour {

    public RectTransform elementSize; //Assigning this to my canvas child panel i want to resize from the editor.
    public float sizingFactor = 0.02f;
    private float startSizeX;
    private float startSizeY;
    private float startX;
    private float startY;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            /*Here it is resizing my panel too 0 or 1 based off of my input not working the way i intended at all
            but i cant quit figure out how to make it do what i want it to do.
            */
            Vector2 position = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
            startX = position.x;
            startY = position.y;
            Debug.Log("Mouse position X = " + startX);
            Debug.Log("Mouse position Y = " + startY);
        }

        if (Input.GetMouseButton(0))
        {
            Vector2 size = new Vector2(elementSize.sizeDelta.x, elementSize.sizeDelta.y);
            size.x = startSizeX + (Input.mousePosition.x - startX) * sizingFactor;
            size.y = startSizeY + (Input.mousePosition.y - startY) * sizingFactor;
            elementSize.sizeDelta = size;
        }
    }
}

Back again i got things working in a predictable way need to add functionality and limits but i find seeing a basic script that does something is easier to understand than seeing a monster script. 1. Create a parent canvas, then create a child panel. 2. Put your resize script on either child or parent i usually put it on the Canvas myself. 3. Assign your child via the inspector as the RectTransfrom.

using UnityEngine;
using System.Collections;

public class ResizeElements : MonoBehaviour {

    public RectTransform elementSize; //Assigning this to my canvas child panel i want to resize from the inspector.

    public float sizingFactor = 0.1f; //How much size we will gain
    public float sizingMagnitude = 100f; //Eventually want to set this via somekind of input Ie: Mouse, drag handles or what ever.

    void Update()
    {
        //Grows our Panel Child when mouse is clicked currently just an example will be adding functionality.
        if (Input.GetMouseButton(0))
        {
            Vector2 size = new Vector2(elementSize.sizeDelta.x, elementSize.sizeDelta.y);
            Debug.Log("size = " + size);
            size.x += sizingFactor * sizingMagnitude;
            Debug.Log("sizingFactor = " + sizingFactor);
            size.y += sizingFactor * sizingMagnitude;
            elementSize.sizeDelta = size;
        }
    }
}