using System.Collections; using System.Collections.Generic; using UnityEngine; public class RotationControl : MonoBehaviour { public Quaternion rotation = new Quaternion(0, 0, 0, 0); public List rotation2 = new List(); public GameObject body; public float min = -15; public float max = 15; public float speed = 0.3f; public float speed2 = 0.3f; public float speed3 = 0.3f; public bool dir = false; public bool dir2 = false; public bool dir3 = false; public bool p = false, r = false, y = false; // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate() { if (p) { if (!dir2 && rotation.x < max) rotation.x += speed2; else if (!dir2) { dir2 = !dir2; rotation.x = (float)max; } else if (dir2 && rotation.x > min) rotation.x -= speed2; else if (dir2) { dir2 = !dir2; rotation.x = (float)min; } } if (r) { if (!dir3 && rotation.y < max) rotation.y += speed3; else if (!dir3) { dir3 = !dir3; rotation.y = (float)max; } else if (dir3 && rotation.y > min) rotation.y -= speed3; else if (dir3) { dir3 = !dir3; rotation.y = (float)min; } } if (y) { if (!dir && rotation.z < max) rotation.z += speed; else if (!dir) { dir = !dir; rotation.z = (float)max; } else if (dir && rotation.z > min) rotation.z -= speed; else if (dir) { dir = !dir; rotation.z = (float)min; } } body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1); for (int index = 0; index < rotation2.Count; ++index) { rotation2[index].GetComponent().rotation = rotation; rotation2[index].GetComponent().FixedUpdate(); } } }