Add this script to an object and every time the object leaves the camera viewport it will return back to its initial position.
Initially, I made it using the Unity functions OnBecameVisible and OnBecameInvisible. The problem is that those functions do not work well with 3D objects with shadows and the camera in perspective mode. So I rewrite it without using those functions. The way I did it was calculating the position of the points in the corners bounds and then check if each point is inside/outside of the camera viewport.
2 Stars:
The code works flawlessly and avoid conflicts with the OnBecameInvisible and shadows issue
1 Wish; the code is quite complicated, wish it was easier to understand
Solve request #96
Add this script to an object and every time the object leaves the camera viewport it will return back to its initial position.
Initially, I made it using the Unity functions OnBecameVisible and OnBecameInvisible. The problem is that those functions do not work well with 3D objects with shadows and the camera in perspective mode. So I rewrite it without using those functions. The way I did it was calculating the position of the points in the corners bounds and then check if each point is inside/outside of the camera viewport.