Edit:
full code for what I did, but I'm a fairly novice programmer and recommend you don't copy this in its entirety, it's probably quite flawed.
public float rotateSpeed;
private Vector3 turnPoint;
private float degX;
private float degZ;
private float direction;
private void Start()
{
degX = 0; // As far as I know, it defaults to 0 without declaration, so this 2 lines aren't necessary
degZ = 0;
}
private void FixedUpdate()
{
Turn("Horizontal", 1, 0, Vector3.back, ref degX);
Turn("Vertical", 0, 1, Vector3.right, ref degZ);
}
private void Turn(string button, int x, int z, Vector3 axis, ref float deg)
{
if (Input.GetButton(button) && degX == 0 && degZ == 0) // So that it only turns in one direction at once
{
direction = Input.GetAxisRaw(button); // Direction needs to be stored for future use
turnPoint = transform.position + new Vector3(0.5f * direction * x, -0.5f, 0.5f * direction * z); // Location of edge
transform.RotateAround(turnPoint, axis, rotateSpeed * direction); // Turn around the edge
deg += rotateSpeed * direction; // How much it has turned so far
}
if (deg != 0) // If the full rotation has not yet been made, repeat
{
transform.RotateAround(turnPoint, axis, rotateSpeed * direction);
deg += rotateSpeed * direction;
if (deg % 90 == 0) // % is a failsafe, deg should ideally be 90 or -90
{
deg = 0;
}
}
}
The way I've done it has it as a method. For now we can just ignore different scale cubes. The parameter button is either "Vertical" or "Horizontal", for now since you're working in 2 dimensions, you can just use "Horizontal" (or the accelerometer input, which I'm not sure how to use). Parameters x and z are used to locate the edge of the cube, but I feel like there's a better way of using this. Axis is just to determine direction of rotation.