forked from nathan-zaloum/BucketCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingCircleSpin.cs
53 lines (37 loc) · 1.93 KB
/
LoadingCircleSpin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LoadingCircleSpin : MonoBehaviour {
//----------------------------------------------------------------------------------------------------------------------------------------------//
private float speed = 300.0f;
private bool fast = false;
private RectTransform rect;
private Image img;
//----------------------------------------------------------------------------------------------------------------------------------------------//
private void Start () {
rect = this.gameObject.transform.GetChild (0).GetComponent<RectTransform> ();
img = this.gameObject.transform.GetChild (0).GetComponent<Image> ();
StartCoroutine (SpeedAdjust ());
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
private void Update () {
if (fast) {
speed = Mathf.Lerp (speed, 500.0f, Time.deltaTime * 25.0f);
img.fillAmount = Mathf.Lerp (img.fillAmount, 0.1f, 25.0f * Time.deltaTime);
} else {
speed = Mathf.Lerp (speed, 250.0f, Time.deltaTime * 25.0f);
img.fillAmount = Mathf.Lerp (img.fillAmount, 0.15f, 25.0f * Time.deltaTime);
}
rect.Rotate (0, 0, speed * Time.deltaTime);
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
private IEnumerator SpeedAdjust () {
fast = false;
yield return new WaitForSeconds (1.0f);
fast = true;
yield return new WaitForSeconds (0.3f);
StartCoroutine (SpeedAdjust ());
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
}