2018-11-10 20:44:41 +01:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2018-11-11 22:26:43 +01:00
|
|
|
public class rotation
|
2018-11-10 20:44:41 +01:00
|
|
|
{
|
2018-11-10 23:54:58 +01:00
|
|
|
public float min = -15;
|
|
|
|
|
public float max = 15;
|
2018-11-10 20:44:41 +01:00
|
|
|
public float speed = 0.3f;
|
2018-11-10 23:54:58 +01:00
|
|
|
public bool dir = false;
|
2018-11-11 22:26:43 +01:00
|
|
|
public bool enabled = true;
|
2018-11-10 23:54:58 +01:00
|
|
|
|
2018-11-11 22:26:43 +01:00
|
|
|
public float i = 0;
|
|
|
|
|
|
|
|
|
|
public rotation(float speed, float min, float max)
|
|
|
|
|
{
|
|
|
|
|
this.speed = speed;
|
|
|
|
|
this.min = min;
|
|
|
|
|
this.max = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float update()
|
|
|
|
|
{
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
if (!dir && i < max)
|
|
|
|
|
{
|
|
|
|
|
i += speed;
|
|
|
|
|
}
|
|
|
|
|
else if (!dir)
|
|
|
|
|
{
|
|
|
|
|
dir = !dir;
|
|
|
|
|
i = (float)max;
|
|
|
|
|
}
|
|
|
|
|
else if (dir && i > min)
|
|
|
|
|
{
|
|
|
|
|
i -= speed;
|
|
|
|
|
}
|
|
|
|
|
else if (dir)
|
|
|
|
|
{
|
|
|
|
|
dir = !dir;
|
|
|
|
|
i = (float)min;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RotationControl : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Vector3 transformation = new Vector3(0, 0, 0);
|
|
|
|
|
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
|
|
|
|
|
|
|
|
|
public Quaternion rotation = new Quaternion(0, 0, 0, 0);
|
|
|
|
|
public List<GameObject> rotation2 = new List<GameObject>();
|
|
|
|
|
public GameObject body;
|
|
|
|
|
public GameObject body2;
|
|
|
|
|
|
|
|
|
|
public rotation r1 = new rotation(0.1f, -15, 15);
|
|
|
|
|
public rotation r2 = new rotation(0.2f, -15, 15);
|
|
|
|
|
public rotation r3 = new rotation(0.3f, -15, 15);
|
|
|
|
|
|
|
|
|
|
public rotation r4 = new rotation(0.01f, -3, 3);
|
|
|
|
|
public rotation r5 = new rotation(0.02f, -3, 3);
|
|
|
|
|
public rotation r6 = new rotation(0.03f, -3, 3);
|
|
|
|
|
|
|
|
|
|
public rotation r7 = new rotation(0.001f, -3, 3);
|
|
|
|
|
public rotation r8 = new rotation(0.002f, -3, 3);
|
|
|
|
|
public rotation r9 = new rotation(0.003f, -3, 3);
|
2018-11-10 20:44:41 +01:00
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
2018-11-10 23:54:58 +01:00
|
|
|
void FixedUpdate()
|
2018-11-10 20:44:41 +01:00
|
|
|
{
|
2018-11-11 22:26:43 +01:00
|
|
|
rotation.x = r1.update();
|
|
|
|
|
rotation.y = r2.update();
|
|
|
|
|
rotation.z = r3.update();
|
2018-11-10 20:44:41 +01:00
|
|
|
|
2018-11-11 22:26:43 +01:00
|
|
|
transformation.x = r4.update();
|
|
|
|
|
transformation.y = r5.update();
|
|
|
|
|
transformation.z = r6.update();
|
2018-11-10 20:44:41 +01:00
|
|
|
|
2018-11-11 22:26:43 +01:00
|
|
|
transformation2.x = r7.update();
|
|
|
|
|
transformation2.y = r8.update();
|
|
|
|
|
transformation2.z = r9.update();
|
2018-11-10 20:44:41 +01:00
|
|
|
|
2018-11-10 23:23:03 +01:00
|
|
|
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
|
2018-11-11 22:26:43 +01:00
|
|
|
body.transform.position = transformation;
|
|
|
|
|
body2.transform.localPosition = transformation2;
|
2018-11-10 20:44:41 +01:00
|
|
|
|
|
|
|
|
for (int index = 0; index < rotation2.Count; ++index)
|
|
|
|
|
{
|
|
|
|
|
rotation2[index].GetComponent<Leg>().rotation = rotation;
|
2018-11-11 22:26:43 +01:00
|
|
|
rotation2[index].GetComponent<Leg>().transformation = transformation;
|
|
|
|
|
rotation2[index].GetComponent<Leg>().transformation2 = transformation2;
|
2018-11-10 23:54:58 +01:00
|
|
|
rotation2[index].GetComponent<Leg>().FixedUpdate();
|
2018-11-10 20:44:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|