- Home /
How to check if a button left the boundaries of a Viewport in ScrollRect?
I'm trying to make an infinite scroll loop, but to do so, I have to know when does the button goes invisible to the screen. If I learn this, then I can fire an event that would recycle that button, and spawn a new one accordingly.
I was planning to use Raycast on the button target, but couldn't make it work. Can I use Raycast on GUI? Are there any alternative solutions to see if a button leaves the boundaries of a panel.
Answer by leSamo · Jan 03, 2018 at 11:13 AM
Yes you can raycast in GUI. Check here: https://docs.unity3d.com/Manual/CameraRays.html and here: https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html
The link itself gives 404, but googled "Unity Camera Rays", found some interesting methods. Can't find a raycast which hits to an area. Are there any ways to cast onto an area?
Eventually avoided the whole Raycast approach, but ins$$anonymous$$d, added 2 objects to act as borders, and recycle/spawn items that according to the order of the buttons. Thanks for the references :D
$$anonymous$$aybe you could simplify this by using $$anonymous$$onoBehaviour.OnBecameVisible() and $$anonymous$$onoBehaviour.OnBecameInvisible().
Couldn't understand how I'd use this? Are there any specific examples for OnBecame methods?
Your answer
![](https://koobas.hobune.stream/wayback/20220612145725im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI, SpellBar and C#-related questions 1 Answer
OnMouseUp() not working like meant 1 Answer
Raycast and GUI question 1 Answer
Distribute terrain in zones 3 Answers
catch GUI click to avoid raycasting after a click? pls help 1 Answer