Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // new cam position = the new position of the Camera.main
  2. public void CameraRepresentationMove(Vector2 newCamPosition)
  3. {
  4. // minicam pos / minimap size = camera pos / map size ; so : local minicam pos = minimap size * camera pos / map size;
  5. float infoX = unitsTexture.width * newCamPosition.x / mapWidth ;
  6. float infoY = unitsTexture.height * newCamPosition.y / mapHeight ;
  7.  
  8. // The scale from all the UI parents - I'll multiply the minimap size with it later
  9. float parentScaleX = unitsImage.transform.parent.GetComponent<RectTransform>().localScale.x * unitsImage.GetComponent<RectTransform>().localScale.x;
  10. float parentScaleY = unitsImage.transform.parent.GetComponent<RectTransform>().localScale.y * unitsImage.GetComponent<RectTransform>().localScale.y;
  11.  
  12. // minicam pos = minimap pos - (minimap height&width/2) * parent scale + local minicam pos * parent scale
  13. 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);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement