using System.Collections; using System.Collections.Generic; using UnityEngine; public class cube_controller_new : MonoBehaviour { float rotSpeed = 90; public int rot_type = 1; // 0: 任意角度 1: 固定90度 public int rot_angle = 0; public string press_key = "Right"; public int press_key_number = 234; GameObject php; void Start() { php = GameObject.Find("PHP"); } void Update() { if (rot_type == 0) { if (Input.GetKey(KeyCode.UpArrow)) { transform.Rotate(this.rotSpeed, 0, 0); } if (Input.GetKey(KeyCode.DownArrow)) { transform.Rotate(-this.rotSpeed, 0, 0); } if (Input.GetKey(KeyCode.LeftArrow)) { transform.Rotate(0, this.rotSpeed, 0); } if (Input.GetKey(KeyCode.RightArrow)) { transform.Rotate(0, -this.rotSpeed, 0); } } if (rot_type == 1) { // 比較Input.GetKey & Input.GetKeyDown的差異性 if (Input.GetKeyDown(KeyCode.UpArrow)) { rot_angle += 90; this.transform.rotation = Quaternion.Euler(new Vector3(rot_angle, 0, 0)); } if (Input.GetKeyDown(KeyCode.DownArrow)) { rot_angle -= 90; this.transform.rotation = Quaternion.Euler(new Vector3(rot_angle, 0, 0)); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { rot_angle -= 90; this.transform.rotation = Quaternion.Euler(new Vector3(0, rot_angle, 0)); } if (Input.GetKeyDown(KeyCode.RightArrow)) { rot_angle += 90; this.transform.rotation = Quaternion.Euler(new Vector3(0, rot_angle, 0)); } } if (Input.GetKey(KeyCode.X)) { upsee(); } if (Input.GetKey(KeyCode.Space)) { //直接旋轉至原點 this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); } } public void upsee() //上視圖 { this.transform.rotation = Quaternion.Euler(new Vector3(-90.0f, 0, 0)); } public void downsee() //下視圖 { this.transform.rotation = Quaternion.Euler(new Vector3(90.0f, 0, 0)); } public void leftsee() //左視圖 { this.transform.rotation = Quaternion.Euler(new Vector3(0, -90.0f, 0)); } public void rightsee() //右視圖 { this.transform.rotation = Quaternion.Euler(new Vector3(0, 90.0f, 0)); press_key = "UP"; press_key_number = 1; php.GetComponent().update_score(); } public void originalsee() // 原點 { this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); //save to database press_key = "Original"; press_key_number = 1; php.GetComponent().update_score(); } }