Shamba

percent

May 2nd, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class percentag_calc : MonoBehaviour {
  7.     public AudioSource Music;
  8.     private float total_time;
  9.     private float present_time;
  10.     public Text Percentage;
  11.     private float perc_float;
  12.     private bool isReached = false;
  13.     public Slider progress;
  14.     // Use this for initialization
  15.     void Start()
  16.     {
  17.  
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         if (isReached == false)
  24.         {
  25.             total_time = Music.clip.length;
  26.             present_time = Music.time;
  27.         }
  28.         perc_float = ((present_time / total_time) * 100);
  29.         if (perc_float == 100)
  30.         {
  31.             isReached = true;
  32.             perc_float = 100;
  33.         }
  34.         if (isReached == true)
  35.         {
  36.             perc_float = 100;
  37.         }
  38.         Percentage.text = perc_float.ToString("0") + "%";
  39.         progress.value = perc_float;
  40.     }
  41. }
Add Comment
Please, Sign In to add comment