Keep gameobject displayed in fix position while changing orthograhicSize

Hi!

I need your help.

I need to have some indicators on the top and bottom screen depending on the y position of a reference object.

The camera orthographicSize changes with the mouse wheel so it makes the indicators go farther and closer. But I want them to be fixed on the top or bottom position.

I have this code

void Update () {
	screenBounds =new Vector2(Camera.main.transform.position.x + 50 , Camera.main.transform.position.y+36);
	screenBounds2 =new Vector2(Camera.main.transform.position.x-50, Camera.main.transform.position.y-36);

	// get myPlayer
	Vector3 targetPostition = new Vector3( this.transform.position.x, reference.transform.position.y, this.transform.position.z);
	
	this.transform.LookAt(targetPostition);
	
	//attach to myPlayer
	Vector3 intiTempPos = new Vector3();
	intiTempPos.x = reference.transform.position.x-10;
	intiTempPos.y = reference.transform.position.y;
	intiTempPos.z = 10;
	
	transform.position = intiTempPos;
	
	//y
	if(intiTempPos.y > screenBounds.y ){
transform.position = new Vector3 (reference.transform.position.x-10, screenBounds.y,-40);
	}
	if(intiTempPos.y < screenBounds2.y){
transform.position = new Vector3(reference.transform.position.x-10, screenBounds2.y,-40 );
		}
	//x
	if(intiTempPos.x > screenBounds.x ){
transform.position = new Vector3 (screenBounds.x-10 , reference.transform.position.y,-40);
	}
	if(intiTempPos.x < screenBounds2.x){
transform.position = new Vector3(screenBounds2.x-10 , reference.transform.position.y,-40 );
		}
	//z
	if(intiTempPos.z < -40){
transform.position = new Vector3(screenBounds2.x-10 , reference.transform.position.y,-40 );
		}

}

Besides what robertbu said, if you want to place something at the borders, you need to calculate where your borders actually are.

You don’t take orthograhicSize into account anywhere.

orthograhicSize is half of the vertical Size of the viewing volume, which means:

float heightInWorldUnits = 2*cam.orthographicSize;
float widthInWorldUnits = heightInWorldUnits * cam.aspect;

I have made what robertbu said and it is working.

I used this coordinates and worked to me…I’ll try with the HappyMoo too.

screenBounds =new Vector2(Camera.main.transform.position.x + 50 , Camera.main.transform.position.y+36);
    screenBounds2 =new Vector2(Camera.main.transform.position.x-50, Camera.main.transform.position.y-36);

Thanks!