我有一個腳本CoinFill
這使得徑向進度條。如何在統一的多個遊戲對象上使用相同的腳本?
當FillAmount = 1時,我想將該特定圖像重置爲零。我希望能夠將這個用於多個GameObject
s。問題是,當第一個FillAmount
= 1,速度更快的一分錢,你可以點擊鎳,可能是在50%填充,然後便士將重置爲0.但是,如果鎳是在1它會不重置自己,只有一分錢會休息。
代碼:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CoinFill : MonoBehaviour {
public SavingsAccountManager sam;
public float fillCoinSpeed;
public Image coinFill;
public float maxCoinFill = 100f;
public float minCoinFill = 0f;
public float currentCoinFill;
// Use this for initialization
void Start()
{
currentCoinFill = minCoinFill;
}
void Update()
{
if (currentCoinFill < maxCoinFill)
{
currentCoinFill += fillCoinSpeed * Time.deltaTime;
}
coinFill.fillAmount = currentCoinFill/maxCoinFill;
}
//Penny Button
public void PennyPush()
{
if (coinFill.fillAmount == 1)
{
sam.savingsAccountAmount += .01f;
sam.savingsAccountText.text = sam.savingsAccountAmount.ToString("f2");
currentCoinFill = minCoinFill;
}
}
//Nickle Button
public void NicklePush()
{
if (coinFill.fillAmount == 1)
{
sam.savingsAccountAmount += .05f;
sam.savingsAccountText.text = sam.savingsAccountAmount.ToString("f2");
currentCoinFill = minCoinFill;
}
}
}
我不知道我是否需要做一些與便士或鎳的父母,或者我應該是使用this
或設置一些家長的事
感謝喬,我最初以爲我可以做這種方式感謝您的幫忙! –
如果它只是一個字符串變量會發生什麼?不拖拉 –
嗨Rifat。不知道你的意思。只需嘗試'公共字符串x',看看會發生什麼。您可以**在編輯器中的插槽中的檢查器中鍵入**字符串。祝你好運 – Fattie