Custom Component

Unity Importer Plugin

Scripting Custom Component
Tips
BindingsLast updated
Was this helpful?


Last updated
Was this helpful?
Was this helpful?
[FigmaComponent("ProgressSpinner")]
public class ProgressSpinner : MonoBehaviour, IFigmaNodeBinder
{
[FigmaNode("Container")]
[SerializeField]
private FigmaNode _container;
public float duration = 1f;
public int period = 12;
public Vector3 axis = Vector3.forward;
private float _periodDuration;
private float _elapsedTime;
private void Start()
{
_periodDuration = duration / period;
StartCoroutine(Rotate());
}
private IEnumerator Rotate()
{
while (true)
{
_elapsedTime += Time.deltaTime;
if (_elapsedTime >= _periodDuration)
{
_elapsedTime -= _periodDuration;
_container.transform.Rotate(axis * (360f / period));
}
yield return new WaitForEndOfFrame();
}
}
public void OnBind(FigmaNode figmaNode)
{
_container.rectTransform.pivot = Vector3.one * 0.5f;
}
}