unity 利用ugui 制作技能冷卻效果


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillItem : MonoBehaviour {

	//冷卻時間
	public float coldTime = 2.0f;

	//定時器
	private float timer = 0f;

	//前面的一張填充圖片
	private Image filedImage;

	//是否開始技能冷卻
	private bool isStartTimer = false;
	// Use this for initialization
	void Start () {
		filedImage = transform.Find ("FilledImage").GetComponent<Image> ();
	}
	
	// Update is called once per frame
	void Update () {
		//已經開始冷卻
		if (isStartTimer) {
			timer += Time.deltaTime;

			//計算fillAmount
			filedImage.fillAmount =	(coldTime - timer) / coldTime;
			if (timer >= coldTime) {

				//停止定時器
				filedImage.fillAmount = 0;
				timer = 0;
				isStartTimer = false;
			}
		}
	}

	public void OnClick()
	{
		isStartTimer = true;
	}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM