Hi, I’m making a game in portrait mode that’s endless. The only control axis is the X axis and I need to set boundaries. I need the boundaries for moving across this axis to be equal to the end of the cameras view on both sides. I’ve tried but with no luck to make a script (C#) that would work, any help would be greatly appreciated!
You can use an if statement along with Camera.ScreenToWorldPoint() to see if an object exceeds the screen boundaries, then set the Transform’s x-position to the boundary position if it does. If the screen size is always the same, you could just use constants instead. The best method may depend on how the object is controlled though. Is it by touch? By button presses?
Posting your code that you’ve tried would help, too. We can see what you did that worked and which parts didn’t work.
I responded to your last thread with an explanation of the math involved. You shouldn’t create duplicate threads. If you can’t get it to work, respond to the open one next time and you’ll get more answers.
Secondly, if you’re looking for code to use, there’s tons of snippets out there. I found this one with a google for “Unity keep on screen”.