Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // new cam position = the new position of the Camera.main
- public void CameraRepresentationMove(Vector2 newCamPosition)
- {
- // minicam pos / minimap size = camera pos / map size ; so : local minicam pos = minimap size * camera pos / map size;
- float infoX = unitsTexture.width * newCamPosition.x / mapWidth ;
- float infoY = unitsTexture.height * newCamPosition.y / mapHeight ;
- // The scale from all the UI parents - I'll multiply the minimap size with it later
- float parentScaleX = unitsImage.transform.parent.GetComponent<RectTransform>().localScale.x * unitsImage.GetComponent<RectTransform>().localScale.x;
- float parentScaleY = unitsImage.transform.parent.GetComponent<RectTransform>().localScale.y * unitsImage.GetComponent<RectTransform>().localScale.y;
- // minicam pos = minimap pos - (minimap height&width/2) * parent scale + local minicam pos * parent scale
- cameraRepresentation.transform.position = unitsImage.transform.position + new Vector3(-parentScaleX * unitsImage.sprite.texture.width / 2, -parentScaleY * unitsImage.sprite.texture.height / 2, 0) + new Vector3(infoX * parentScaleX, (infoY + unitsImage.sprite.texture.height)* parentScaleY, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement