Skip to content

Instantly share code, notes, and snippets.

@reidscarboro
Created May 10, 2017 13:29
Show Gist options
  • Save reidscarboro/588911e7bc0e0ad82bfa8a1ad2397bd5 to your computer and use it in GitHub Desktop.
Save reidscarboro/588911e7bc0e0ad82bfa8a1ad2397bd5 to your computer and use it in GitHub Desktop.
Bouncing loading dots in Unity using DoTween
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class LoadingDots : MonoBehaviour {
//the total time of the animation
public float repeatTime = 1;
//the time for a dot to bounce up and come back down
public float bounceTime = 0.25f;
//how far does each dot move
public float bounceHeight = 10;
public List<GameObject> dots;
void Start(){
if (repeatTime < dots.Count * bounceTime){
repeatTime = dots.Count * bounceTime;
}
InvokeRepeating("Animate", 0, repeatTime);
}
void Animate(){
for (int i = 0; i < dots.Count; i++){
int dotIndex = i;
dots[dotIndex].transform
.DOMoveY(dots[dotIndex].transform.position.y + bounceHeight, bounceTime / 2)
.SetDelay(dotIndex * bounceTime / 2)
.SetEase(Ease.OutQuad)
.OnComplete(() =>
{
dots[dotIndex].transform
.DOMoveY(dots[dotIndex].transform.position.y - bounceHeight, bounceTime / 2)
.SetEase(Ease.InQuad);
});
}
}
}
@reidscarboro
Copy link
Author

Preview: dots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment