// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.LeftArrow) && !isRotating) { direction = 1; isRotating = true; } if (Input.GetKeyDown(KeyCode.RightArrow) && !isRotating) { direction = -1; isRotating = true; } if (isRotating) { angleRotated += direction * 90 * Time.deltaTime * speed; if (Math.Abs(angleRotated) < 90) { this.transform.RotateAround(new Vector3(0, 0, 0), new Vector3(0, 1, 0), direction * 90 * Time.deltaTime * speed); } else { this.transform.RotateAround(new Vector3(0, 0, 0), new Vector3(0, 1, 0), direction * 90 - previousAngleRotate); } if (Math.Abs(angleRotated) >= 90) { isRotating = false; orientation = (TowerOrientation)((int)(orientation + direction) % 4); direction = 0; angleRotated = 0; } previousAngleRotate = angleRotated; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.LeftArrow) && !isRotating) { angleRotated = 0; isRotating = true; } if (isRotating) { angleRotated += 90 * Time.deltaTime * speed; this.transform.RotateAround(new Vector3(0, 0, 0), new Vector3(0, 1, 0), (angleRotated < 90) ? 90 * Time.deltaTime * speed : 90 - previousAngleRotate); if (angleRotated >= 90) { isRotating = false; orientation = (TowerOrientation)((int)(orientation + 1) % 4); } previousAngleRotate = angleRotated; } }
void Start() { orientation = 0; }