- Home /
Question by
Nero R · Sep 17, 2015 at 04:45 PM ·
camerascript.boundsortographic
put prefab in top left of the camera
I am trying to put a prefab in the top left corner of the camera, i have the next 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);
}
}
Everything is working ok but for some reason i get the portrait a lil bit too on the left, whats wrong with the code and why it works only on the Y axis?
graphical description of the problem:
problem.png
(9.0 kB)
Comment