I am trying to put a portrait in the top left side of the camera, here is my code:
Encounter encounter;
Party party;
public Portrait portraitPrefab;
Portrait[] Enemies;
// Use this for initialization
void Start () {
encounter = EncounterStatic.encounter;
Enemies = new Portrait[encounter.getEnemies().Length];
Renderer portraitRenderer = portraitPrefab.GetComponent<Renderer> ();
float portraitWidth = portraitRenderer.bounds.size.x;
float portraitHeight = portraitRenderer.bounds.size.y;
Bounds bound = CameraExtensions.OrthographicBounds (Camera.main);
float posX = bound.center.x - bound.extents.x + portraitWidth / 2;
float posY = bound.center.y + bound.extents.y - portraitHeight / 2;
Vector3 upperLeft = new Vector3 (posX,posY,0);
for (int i=0; i<encounter.getEnemies().Length; i++) {
Portrait newEnemy = (Portrait)Instantiate(portraitPrefab,upperLeft,transform.rotation);
}
}
but it ends like this:
Any idea why its working ok for the Y axis but wrong for the X axis?
Ah here is the code to get the bounds:
public static Bounds OrthographicBounds(Camera camera)
{
float screenAspect = (float)Screen.width / (float)Screen.height;
float cameraHeight = camera.orthographicSize * 2;
Bounds bounds = new Bounds(
camera.transform.position,
new Vector3(cameraHeight * screenAspect, cameraHeight, 0));
return bounds;
}