반응형
Notice
Recent Posts
Recent Comments
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

Do Something IT

숫자 카운팅 본문

Unity3D

숫자 카운팅

아낙시만더 2015. 7. 8. 16:20
반응형

아래와 같이 작성하여 숫자 카운팅을 나타 낼수 있다.



 using UnityEngine;
 using System.Collections;
 
 public class ScoreCounter : MonoBehaviour 
 {
     public float duration = 0.5f;
     int score = 0;
     
     void OnGUI () {
         GUIButtonCountTo (0);
         GUIButtonCountTo (5000);
         GUIButtonCountTo (20000);
         GUILayout.Label ("Current score is " + score);        
     }
 
     void GUIButtonCountTo (int target) {
         if (GUILayout.Button ("Count to " + target)) {
             StopCoroutine ("CountTo");
             StartCoroutine ("CountTo", target);
         }
     }
     
     IEnumerator CountTo (int target) {
         int start = score;
         for (float timer = 0; timer < duration; timer += Time.deltaTime) {
             float progress = timer / duration;
             score = (int)Mathf.Lerp (start, target, progress);
             yield return null;
         }
         score = target;
     }
 }
반응형
Comments