VariableData.cs
1    using System.Collections;
2    using System.Collections.Generic;
3    using UnityEngine;
4    using TMPro;
5    using UnityEngine.UI;
6    
7    public class VariableData : MonoBehaviour
8    {
9        [Header("Input")]
10       public Dropdown inputGear;
11       public Dropdown outputGear;
12   
13       public Slider lengthSlider;
14       public Slider velocitySlider;
15   
16       public Rigidbody2D rb;
17   
18       //stored data
19       private int inGear;
20       private int outGear;
21       private float length;
22       private float velocity; //circular, rpms
23   
24       Ratio r;
25   
26       float torque = 2.1f;
27   
28   
29       public bool active;
30   
31       [Header("Output")]
32       public TextMeshProUGUI ratioOutput;
33       public TextMeshProUGUI velOutput;
34   
35       public TextMeshProUGUI torqueOutput;
36   
37       [Header("Cross data")]
38       public Timeline timeline;
39   
40       public void Reset()
41       {
42           timeline.play = false;
43           timeline.timelineSlider.value = 0;
44   
45           inGear = int.Parse(inputGear.options[inputGear.value].text);
46           outGear = int.Parse(outputGear.options[outputGear.value].text);
47   
48           r = new Ratio(inGear, outGear);
49           r.Simplify();
50   
51           ratioOutput.text = r.ratioString;
52           active = true;
53       }
54   
55       private void Update()
56       {
57           if(active)
58           {
59               SpinCalculations();
60           }
61       }
62   
63       private void SpinCalculations()
64       {
65           float torqueMod = r.numerator;
66           float speedMod = r.denominator;
67   
68           velocity = velocitySlider.value - 600;
69   
70           float circularVelFinal = (speedMod/torqueMod) * velocity;
71           float torqueFinal = (torqueMod / speedMod) * torque;
72   
73           rb.angularVelocity = circularVelFinal;
74   
75           velOutput.text =( (int) circularVelFinal).ToString();
76           torqueOutput.text = torqueFinal.ToString();
77       }
78   }
79