Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class percentag_calc : MonoBehaviour {
- public AudioSource Music;
- private float total_time;
- private float present_time;
- public Text Percentage;
- private float perc_float;
- private bool isReached = false;
- public Slider progress;
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (isReached == false)
- {
- total_time = Music.clip.length;
- present_time = Music.time;
- }
- perc_float = ((present_time / total_time) * 100);
- if (perc_float == 100)
- {
- isReached = true;
- perc_float = 100;
- }
- if (isReached == true)
- {
- perc_float = 100;
- }
- Percentage.text = perc_float.ToString("0") + "%";
- progress.value = perc_float;
- }
- }
Add Comment
Please, Sign In to add comment