Hello, I had to write this article again because it was somehow forgotten
i
You’re definitely not checking for an object being offscreen with that code. It looks like the if statement would be true anytime the object’s position is anywhere left of a point far to the right off the screen, which of course means all points on the screen are included. (That’s assuming your camera’s lower left is (0,0) which is not a guaranteed assumption, but if that’s not the case then this code is just more nonsensical)
Generally you should do something like:
void Update() {
Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position);
if (screenPos.x > Screen.width) {
Debug.Log("Off the right side");
}
if (screenPos.x < 0) {
Debug.Log("Off the left side");
}
}
1 Like
it works, thank you so much