Search Unity

sprite scaling problem

Discussion in 'Scripting' started by JacobJGrant, Feb 21, 2017.

  1. JacobJGrant

    JacobJGrant

    Joined:
    Jul 4, 2016
    Posts:
    9
    Hi guys, I am trying to move a sprite around when I click on a inventory item and then put it back into the slot.
    The problem I am having is that when I pick up the inventory sprite, its massive on the screen.
    I need to be able to scale it properly but I just cant seem to get it to work. Here is the code.


    //The hoverObject's position
    Vector2 position;

    //Translates the mouse screen position inot a local position and stores it in the position
    RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out position);


    //Adds the offset to the position
    position.Set(position.x, position.y - hoverYOfset);

    //Sets the hoverObjects position
    hoverObject.transform.position = canvas.transform.TransformPoint(position);

    here is another example of the same function.

    float xm = Input.mousePosition.x;
    float ym = Input.mousePosition.y;

    hoverObject.transform.position = new Vector2(xm + 1, ym + 1);

    Any suggestions??