I am developing a game in which at a certain point iam limiting the rotation of a particular GameObject to a certain minimum and maximum value using Mathf.Clamp.
Here is the Scripting Part:
Vector3 currentRotation = Pillar.transform.rotation.eulerAngles;
float dummyY = currentRotation.y;
float dummyX = currentRotation.x;
if (Mathf.Abs (dummyX - 360f) < 1f)
{
dummyX = 0f;
}
float newRotationY = dummyY;
float newRotationX = dummyX;
if (Up)
{
newRotationX = dummyX - Time.deltaTime * rotationSpeed;
}
if (Down)
{
newRotationX = dummyX + Time.deltaTime * rotationSpeed;
}
if (RotationUp)
{
newRotationX = dummyX + Time.deltaTime * rotationSpeed;
}
if (RotationDown)
{
newRotationX = dummyX + Time.deltaTime * rotationSpeed;
}
newRotationY = Mathf.Clamp (newRotationY, -359.99f, 359.99f);
newRotationX = Mathf.Clamp (newRotationX, -40f, 60f);
if (Pillar2.transform.rotation.x < -40.0f)
{
Pillar2.transform.rotation = Quaternion.Euler(-40.0f, 0, 0);
}
currentRotation.y = newRotationY;
currentRotation.x = newRotationX;
Pillar.transform.rotation = Quaternion.Euler (currentRotation);
Now the weird problem iam facing is that this scripts work perfectly on windows and android phones with Oreo 8.0 OS.. but on devices with andriod 7.0 or below.. My Mathf.Clamp function doesnt seem to work properly. It behaves by breaking the min and max limits and rotating on loop if the button is being kept pressed. Iam using the unity version 2017.1.0p4 and also have updated the SDK to the highest available API level till 8.0 OS. Any help or alternate solution for this problem will be highly appreciated.
↧