Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Small_Rings : MonoBehaviour {
- public AnimationCurve FrontRingCurve;
- public float TimeEval;
- public GameObject FrontRing;
- public GameObject RearRing;
- public double AddSpeed;
- public GameObject[] Rings;
- public float Front_OldAngle;
- public float FrontAngleAdd;
- public ConstantForce RearForce;
- public bool AddRandomForce;
- // Update is called once per frame
- void Update ()
- {
- int i = 0;
- foreach (GameObject Ring in Rings)
- {
- i++;
- //Ring.transform.localEulerAngles = new Vector3(Mathf.Lerp(FrontRing.transform.localEulerAngles.x, RearRing.transform.localEulerAngles.x, i * 0.1f), 90, 90);
- Ring.transform.localRotation = Quaternion.Slerp(FrontRing.transform.rotation, RearRing.transform.rotation, i * 0.1f);
- }
- RearForce.relativeTorque = new Vector3(0, 0, 0);
- if (TimeEval < 1)
- TimeEval += Time.deltaTime * 2;
- if (TimeEval > 1)
- TimeEval = 1;
- FrontRing.transform.localEulerAngles = new Vector3(FrontRingCurve.Evaluate(TimeEval), 90, 90);
- if (AddRandomForce && TimeEval >= 1)
- {
- AddRandomForce = false;
- AddForce();
- }
- }
- public void AddForce()
- {
- int RandomNumber = Random.Range(0, 5);
- Front_OldAngle = FrontRing.transform.localRotation.eulerAngles.x;
- switch (RandomNumber)
- {
- case 0:
- FrontAngleAdd = -45;
- break;
- case 1:
- FrontAngleAdd = -45;
- break;
- case 2:
- FrontAngleAdd = 0;
- break;
- case 3:
- FrontAngleAdd = 45;
- break;
- case 4:
- FrontAngleAdd = 45;
- break;
- }
- FrontRingCurve = AnimationCurve.EaseInOut(0, Front_OldAngle, 1, Front_OldAngle + FrontAngleAdd);
- TimeEval = 0;
- float ran = Random.Range(-5, 5);
- if (ran < 1 && ran > -1)
- {
- ran = Random.Range(-5, 5);
- }
- RearForce.relativeTorque = new Vector3(0, ran * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement