Advertisement
CassataGames

Untitled

Sep 21st, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Small_Rings : MonoBehaviour {
  6.  
  7.     public AnimationCurve FrontRingCurve;
  8.     public float TimeEval;
  9.  
  10.     public GameObject FrontRing;
  11.     public GameObject RearRing;
  12.  
  13.     public double AddSpeed;
  14.  
  15.     public GameObject[] Rings;
  16.  
  17.     public float Front_OldAngle;
  18.     public float FrontAngleAdd;
  19.  
  20.     public ConstantForce RearForce;
  21.  
  22.     public bool AddRandomForce;
  23.    
  24.     // Update is called once per frame
  25.     void Update ()
  26.     {
  27.         int i = 0;        
  28.         foreach (GameObject Ring in Rings)
  29.         {
  30.             i++;
  31.             //Ring.transform.localEulerAngles = new Vector3(Mathf.Lerp(FrontRing.transform.localEulerAngles.x, RearRing.transform.localEulerAngles.x, i * 0.1f), 90, 90);
  32.             Ring.transform.localRotation = Quaternion.Slerp(FrontRing.transform.rotation, RearRing.transform.rotation, i * 0.1f);
  33.         }
  34.  
  35.         RearForce.relativeTorque = new Vector3(0, 0, 0);
  36.  
  37.         if (TimeEval < 1)
  38.             TimeEval += Time.deltaTime * 2;
  39.         if (TimeEval > 1)
  40.             TimeEval = 1;
  41.  
  42.         FrontRing.transform.localEulerAngles = new Vector3(FrontRingCurve.Evaluate(TimeEval), 90, 90);
  43.  
  44.         if (AddRandomForce && TimeEval >= 1)
  45.         {
  46.             AddRandomForce = false;
  47.             AddForce();
  48.         }
  49.     }
  50.  
  51.     public void AddForce()
  52.     {
  53.         int RandomNumber = Random.Range(0, 5);
  54.         Front_OldAngle = FrontRing.transform.localRotation.eulerAngles.x;
  55.         switch (RandomNumber)
  56.         {
  57.             case 0:
  58.                 FrontAngleAdd = -45;
  59.                 break;
  60.             case 1:
  61.                 FrontAngleAdd = -45;
  62.                 break;
  63.             case 2:
  64.                 FrontAngleAdd = 0;
  65.                 break;
  66.             case 3:
  67.                 FrontAngleAdd = 45;
  68.                 break;
  69.             case 4:
  70.                 FrontAngleAdd = 45;
  71.                 break;
  72.         }
  73.         FrontRingCurve = AnimationCurve.EaseInOut(0, Front_OldAngle, 1, Front_OldAngle + FrontAngleAdd);
  74.         TimeEval = 0;
  75.         float ran = Random.Range(-5, 5);
  76.         if (ran < 1 && ran > -1)
  77.         {
  78.             ran = Random.Range(-5, 5);
  79.         }
  80.         RearForce.relativeTorque = new Vector3(0, ran * 100);
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement