First of all, i am not so familiar with scripting, becaus i come from the design perspektiv. What i try to do is a touch control to view an object. so far, it works by using the following script:
but now i want to limit the rotation to 90 degrees up and down. I tought about clamping the rotation, but i didn*t get, how to clamp that quoternian right.
Thanks for any help.
Don’t do this! Euler angles suck. It won’t reliably give you a useful value for this kind of functionality. (It sometimes will, but it may unexpectedly break at some point, for the reasons detailed in the linked article.)
I recommend having a Vector2 variable representing the amount you have dragged; you can safely use Mathf.Clamp on this value to limit your rotation. This value can then be applied to your transform’s rotation using Quaternion.AngleAxis (make sure this is a one-way street though!)
(Apologies for weird indentation, I typed it up in the input box and can’t tab.)
You really only need a float for your Y rotation, but I assume at some point you’ll probably want to add in X as well, so a Vector2 will let you add that easily.