Search code examples
c#unity-game-enginegame-physicsunityscript

How To Apply Bounds in Unity For iOS devices


I've made an unity game for iOS devices. It has a game object(sphere) which moves by the force applied to it. But I want to limit the sphere within the screen bounds.

I've seen the unity reference to Bounds, but i don't know how apply it according to the iOS device screens. Please Help.

ThankYou.


Solution

  • Use Mathf.clamp to keep your movement within the screen size. This will be more efficient than using colliders on the edges of your screen. Just play around with your object until you get the right numbers to keep it on your screen. Of course if you plan to use iOS tablets etc you will need to be able to account for the change in your clamping area.

    Here is a link to the Unity Documentation which actually includes an example of what you are trying to do.

    http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Clamp.html