While hitting the border the y coordinates decreases multiple times.

In below code , I have defined drop position as 1.But when the object hits the border the newPosition.y is getting called multiple times. This behaviour is irregular. I want it to reduce the value by 1 each time it hits the border.

if (Camera.main.WorldToScreenPoint(transform.position).x > Screen.width) {
		newPosition.y = transform.position.y-dropPosition;
		transform.position = newPosition;
		direction = -1;
	}
	else if(Camera.main.WorldToScreenPoint(transform.position).x < 0){
		newPosition.y = transform.position.y-dropPosition;
		transform.position = newPosition;
		direction = 1;
	}

Hello,
you can use direction to check if it’s in screen

if (Camera.main.WorldToScreenPoint(transform.position).x > Screen.width && (direction != -1)) 
{
	 newPosition.y = transform.position.y-dropPosition;
	 transform.position = newPosition;
	 direction = -1;
 }
 else if(Camera.main.WorldToScreenPoint(transform.position).x < 0 && (direction != 1))
 {
	 newPosition.y = transform.position.y-dropPosition;
	 transform.position = newPosition;
	 direction = 1;
 }

Please provide more context. What are you trying to accomplish? Where is this code being executed?

There’s not an information to really begin to answer your question yet, but I’m guessing you’re doing this check in Update() and the object’s y value is being decremented many times per frame anytime your object’s x position is not between 0 and Screen.width.