Created
May 10, 2017 13:29
-
-
Save reidscarboro/588911e7bc0e0ad82bfa8a1ad2397bd5 to your computer and use it in GitHub Desktop.
Bouncing loading dots in Unity using DoTween
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preview: