public class TachoMaker : MonoBehaviour
{
public float numbers = 8;
private float instDeg;
private float instdegnew;
private bool tachoSwitch = true;
private float numberReg;
public GameObject tachoscales;
public Transform tachographParent;
void Start()
{
numbers += 1; // + 1 so i doesn't fuck up
instDeg = 280f / numbers; // aligne around 280degree
instdegnew = -40f;// start degree
}
void Update()
{
if (tachoSwitch)
{
for (int i = 0; i < numbers; i++) // for loop for every 1000 rpm scale
{
if (i != 0) // if block so the first sclae is placed at start degree
{
instdegnew -= instDeg;
}
GameObject clone = Instantiate(tachoscales, tachographParent); // creating and making parent
Text tachographnumber = clone.GetComponentInChildren<Text>();
RectTransform rt = clone.GetComponent<RectTransform>();
if (tachographnumber != null) // if there is a child
{
tachographnumber.text = i.ToString(); // changing number according rpm number
tachographnumber.rectTransform.localRotation = Quaternion.Euler(0, 0, -instdegnew); // realigning number so its clear
}
rt.localRotation = Quaternion.Euler(0, 0, instdegnew); // adding rotation to scale
rt.anchoredPosition = Vector2.zero; // pivot in the middle of parrent
rt.localScale = Vector3.one;
}
tachoSwitch = false; //so it only runs once
}
}
}