Can somebody EXPLAIN this code form level zero

Explain this things only - ScreenPointToLocalPointInRectangle, localPoint, minimapRect.rect, minimapRect.rect.x.

Vector2 mousePos = Mouse.current.position.ReadValue();

    if(!RectTransformUtility.ScreenPointToLocalPointInRectangle
        (minimapRect, mousePos, null, out Vector2 localPoint )) { return; }

    Vector2 lerp = new Vector2(
        (localPoint.x - minimapRect.rect.x) / minimapRect.rect.width,
        (localPoint.y - minimapRect.rect.y) / minimapRect.rect.height);


    
    Vector3 newCameraPos = new Vector3(
        Mathf.Lerp(-mapScale, mapScale, lerp.x),
        playerCameraTransform.position.y,
        Mathf.Lerp(-mapScale, mapScale, lerp.y));

Hi there,
ScreenPointToLocalPointInRectangle returns true if the point is inside the rect. So this is check if the mouse click is inside the rect of the minimap.
localPoints are local coordinates relative to to the gameobject (in this case the minimap). So the (0,0,0) point would be the zero point of the minimap (as opposed to the zero point of the screen).
miniMapRect is the transform of the miniMap. This has the data regarding the bounds of the rectangle that make up the miniMap include it’s position and rotation.
miniMapRect.rect accesses the 2D rectangle specific information.
miniMapRect.rect.x/y are the x and y coordinate of the upper left corner of the rect.

Lerp is using this information to calculate the relative distance across the minimap in the x and y as a percentage.
The new camera position uses this percentage and applies it to the full size of the map.

Let me know if this answers you question.

Ok thanks i understood

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms