I'm working on a simple puzzle-style Unity game for iOS. The game presents the user a "rubiks cube" object (one large cube comprised of smaller cubes).
I want users to be able to swipe left/right/up/down on the cube to rotate as expected.
My code works, but after the user performs a 2nd rotation, the cube does not rotate according to the user's expected direction. After the first rotation, the x/y/z axis have rotated along with the device.
If I only use the left/right swipe code, it works as expected. When I add up/down swiping, it breaks. Which makes sense, since the axis doesn't rotate when I stick to two variables.
Here is my code:
if (Input.GetMouseButtonUp(0))
{
//swipe upwards
if (currentSwipe.y > 0 && currentSwipe.x > -1f && currentSwipe.x < 1f)
{
GameObject.FindGameObjectWithTag("Sfx").GetComponent<SoundManager>().PlaySwipe();
gameObject.transform.DORotateQuaternion(Quaternion.Euler(0f, 0f, 90f), 0.5f).SetRelative(true).OnComplete(SetSwiping);
}
//swipe down
if (currentSwipe.y < 0 && currentSwipe.x > -1f && currentSwipe.x < 1f)
{
GameObject.FindGameObjectWithTag("Sfx").GetComponent<SoundManager>().PlaySwipe();
gameObject.transform.DORotateQuaternion(Quaternion.Euler(0f, 0f, -90f), 0.5f).SetRelative(true).OnComplete(SetSwiping);
}
//swipe left
if (currentSwipe.x < 0 && currentSwipe.y > -1f && currentSwipe.y < 1f)
{
GameObject.FindGameObjectWithTag("Sfx").GetComponent<SoundManager>().PlaySwipe();
gameObject.transform.DORotateQuaternion(Quaternion.Euler(0f, -90f, 0f), 0.5f).SetRelative(true).OnComplete(SetSwiping);
}
//swipe right
if (currentSwipe.x > 0 && currentSwipe.y > -1f && currentSwipe.y < 1f)
{
GameObject.FindGameObjectWithTag("Sfx").GetComponent<SoundManager>().PlaySwipe();
gameObject.transform.DORotateQuaternion(Quaternion.Euler(0f, 90f, 0f), 0.5f).SetRelative(true).OnComplete(SetSwiping);
}
}
Any help is appreciated! I'm relatively new to Unity so still learning.
DORotateQuaternion. Where did you get that one from? Perhaps you could add a few pictures so we could understand your problem better.