Hi!
I need to detect whenever my player is near the screen edge of my 2D game. I got some code but that only works for the left side and for the bottom. I need to be able to detect for all of the edges. How can I do such a thing?
Here’s my code so far:
void Update()
{
Vector3 screenPos = Camera.main.WorldToScreenPoint(this.transform.position);
if (transform.position.x > screenPos.x || transform.position.y > screenPos.y)
{
gc.PlayerDie();
}
}
I know there’s a problem with it but I can’t not solve it.
Any help is appreciated! Also, please try and post code in C# if code is necessary.
Thanks in advance!