LSBUGPG / UnityLibrary

A library of useful Unity components and test scenes
GNU General Public License v3.0
0 stars 0 forks source link

Add endless scrolling to an object #122

Closed ghost closed 7 years ago

ghost commented 7 years ago

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.

leobyt commented 7 years ago

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