private void Update() { //看板を動かす switch (RotateState) { case ERotateState.InX: case ERotateState.InY: case ERotateState.InZ: if (NearPillar) { NearPillar.transform.parent.GetComponent <Pillar>().IsIndicate = true; } break; default: break; } //Debug.Log(rotateRad); //回転 if (InputUtil.IsPushButton(KeyCode.Space)) { //共通処理 switch (RotateState) { case ERotateState.InX: case ERotateState.InY: case ERotateState.InZ: if (!isStartedRotate) { StartRotate(); } rotateRad += rotateSpeed * (Time.fixedDeltaTime * 60); break; default: break; } //位置制御 switch (RotateState) { case ERotateState.InX: _rigidbody.position = new Vector3( prevRotatePos.x, NearPillar.transform.position.y + (prevRotatePos.y - NearPillar.transform.position.y) * Mathf.Cos(rotateRad * Mathf.Deg2Rad), (prevRotatePos.y - NearPillar.transform.position.y) * Mathf.Sin(rotateRad * Mathf.Deg2Rad) ); break; case ERotateState.InY: _rigidbody.position = new Vector3( NearPillar.transform.position.x + (prevRotatePos.x - NearPillar.transform.position.x) * Mathf.Cos(rotateRad * Mathf.Deg2Rad), prevRotatePos.y, (prevRotatePos.x - NearPillar.transform.position.x) * Mathf.Sin(rotateRad * Mathf.Deg2Rad) ); break; case ERotateState.InZ: float mag = (prevRotatePos - NearPillar.transform.position).magnitude; float x = prevRotatePos.x - NearPillar.transform.position.x; float y = prevRotatePos.y - NearPillar.transform.position.y; _rigidbody.position = new Vector3( NearPillar.transform.position.x + mag * Mathf.Cos(Mathf.Atan2(y, x) + rotateRad * Mathf.Deg2Rad), NearPillar.transform.position.y + mag * Mathf.Sin(Mathf.Atan2(y, x) + rotateRad * Mathf.Deg2Rad), 0 ); break; default: break; } } else { if (!isEndedRotate) { switch (RotateState) { case ERotateState.InX: case ERotateState.InY: case ERotateState.InZ: _rigidbody.useGravity = true; isStartedRotate = false; isEndedRotate = true; break; default: break; } switch (RotateState) { case ERotateState.InX: if (IsFrontArea()) { _rigidbody.position = new Vector3( prevRotatePos.x, NearPillar.transform.position.y + (prevRotatePos.y - NearPillar.transform.position.y) * Mathf.Cos(0), 0 ); } else { _rigidbody.position = new Vector3( prevRotatePos.x, NearPillar.transform.position.y + (prevRotatePos.y - NearPillar.transform.position.y) * Mathf.Cos(180), 0 ); } break; case ERotateState.InY: if (IsFrontArea()) { _rigidbody.position = new Vector3( NearPillar.transform.position.x + (prevRotatePos.x - NearPillar.transform.position.x) * Mathf.Cos(0), prevRotatePos.y, 0 ); } else { _rigidbody.position = new Vector3( NearPillar.transform.position.x + (prevRotatePos.x - NearPillar.transform.position.x) * Mathf.Cos(180), prevRotatePos.y, 0 ); } break; case ERotateState.InZ: //補正必要なし break; default: break; } AddCentifugalForce(RotateState, IsFrontArea()); } //左移動 if (InputUtil.IsPushButton(KeyCode.LeftArrow)) { _rigidbody.velocity -= speed; } //右移動 if (InputUtil.IsPushButton(KeyCode.RightArrow)) { _rigidbody.velocity += speed; } //上移動 if (InputUtil.IsPushButtonDown(KeyCode.UpArrow)) { _rigidbody.velocity += jumpPower; } //z軸固定 if (_rigidbody.position.z != 0) { Vector3 tmp = _rigidbody.position; _rigidbody.position = new Vector3(tmp.x, tmp.y, 0); } } }