DAY 15
0
Mobile Development

## 面的旋轉

### 旋轉到正確角度

• 新增布林變數控制是否自動旋轉
• 新增Quaternion來儲存數值
``````private bool autoRotating = false;
private Quaternion targetQuaternion;
``````

RotateToRightAngle()函式中:

• 新增vue變數紀錄旋轉角度
• 使用Mathf.Round()來得到最靠近90的角度
``````  public void RotateToRightAngle()
{
Vector3 vec = transform.localEulerAngles;

vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;

targetQuaternion.eulerAngles = vec;
autoRotating = true;
}
``````

### 自動旋轉

``````private float speed = 300f;
``````

AutoRotate()中:

• 計算旋轉一步的時間
• 如果開始旋轉，旋轉到底
• 旋轉角度
• 更新面的狀態及布林值
``````private void AutoRotate()
{
dragging = false;
var step = speed * Time.deltaTime;
transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetQuaternion, step);

//如果開始旋轉，旋轉到底
if (Quaternion.Angle(transform.localRotation, targetQuaternion) <= 1)
{
transform.localRotation = targetQuaternion;

autoRotating = false;
dragging = false;
}
}
``````

`````` if (autoRotating)
{
AutoRotate();
}
``````

### 取消選取

``````   public void PutDown(List<GameObject> littleCubes, Transform pivot)
{
foreach (GameObject littleCube in littleCubes)
{
if (littleCube != littleCubes[4])
{
littleCube.transform.parent.transform.parent = pivot;
}
}
}
``````

``````cubeState.PutDown(activeSide, transform.parent);
``````

## 遊戲機制

### 碰撞

`````` private void OnTriggerEnter(Collider other)
{
Debug.Log("Coll" + other.gameObject.name);
}
``````

### 場景切換

``````//場景轉換
``````
``````//重新開始