From 12775c8ef7a08248b2c1fd6d1c8f5f255ac54623 Mon Sep 17 00:00:00 2001 From: Shaun M Reed Date: Sat, 26 Aug 2017 18:31:01 -0400 Subject: [PATCH] Reworked ExperienceBar.cs -Alters expBarSprite's fill amount according to % ( exp gained / required ) -Scales according to viewport -Used Mathf.Lerp() to smooth bar growth over time.deltatime * lerpSpeed -Added clicks integer to keep track of total clicks Needs: -Delevel if ExpLess() called until expObtained < previousExpRequired -Create function to query for previous and future level requirements returned and stored within structs --- Assets/Scenes/Main.unity | Bin 104752 -> 106000 bytes Assets/Scripts/ExperienceBar.cs | 88 ++++++++++++++++---------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index b2ec4bcc32b7713a351538dbb3ba31c8d2e13e1a..0f8e8c117fb9d27e439d61249a7172faf5fadd44 100644 GIT binary patch delta 2467 zcmbVNVN6q36uzfa=%mGB&439Lux#jklaz4 z9lgEwuM@TRTrpL@tezci6#n$BRB@Go_`-QepvE4Doi@O~BZT;tpil7^D2OeDFGru^ zGbxCT;)Q6f*tOW>Iam+_30(C2n79|Ec{!#E{T(c3mK2jnW9B4HilKRT;h6F#W2cSs z|BQGO=WWiYbJ(`q9K_~zuG;7>wO8B9sK45_wZ`s3f0NzeSXQ;ArrJ#`7Pl+Qm{(e5 zTeWes&Fao3($Zp^H#E1RsoEwATJh`zz^mTQ?ysXd|%?FwA_K5IsnTL@qJR(nClp#!%ux zhItWl<2V6(=CSqFXvhP^_M)XZvKZz&Lr5!*F-J8qF);NjOrnwxAe&)}d*#GB3|`8x z{5~adxy$XuDdI$|7A;Lu!LSF2g*IYmSR+^1WiWM}Qy5}R=B<<=h?o&AJ#NqDO%kR# zPssZ?rmS9uwQxte40Y)jlv;PN8S_P@);Aeu=~pr(?sRQKBH~4i(o@zXhCM(mRBJNB z8V7JKicVk0Y=*U8lK7$|)%TD8DiMxy%T5{UHVjT^N&;*~a~b7ik~T9e_KH&G0fwc1 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ABQly;NJk@O4!(S6ND)@CXp%-fJV4j9Ab|t9Y1VV z7qTx29Ln;gOm(HC&IJrKbHc3LzTyMiGx)Q%N1m-kx9kNs2BH{<27m2LGhvf4g}w`I z@2nwaoL`Rhx%m7ZoIiVf#>?jsO7GPiBW}7eS*#@gWfn=>F($qNz zYqtPTDlbIC9x%yS`LG3t=C$h3tF0E-LLRqC>QJiU{2D=gmEzKcmhk z#s+j&1ch5K3G1JJ_9lnmHy=yud+?s_3cQZKoxs<&D5-+dfP$&u>Y7I)3(gCq1{().sizeDelta = new Vector3(barPosition, barHeight); + fillAmount = 0; } // Update is called once per frame void Update () { - //Check if Exp bar is full - if(this.gameObject.GetComponent().sizeDelta.x == barWidth || expBar.GetComponent().sizeDelta.x > barWidth) + if (fillAmount != expBarSprite.fillAmount) + { + expBarSprite.fillAmount = Mathf.Lerp(expBarSprite.fillAmount, fillAmount, Time.deltaTime * lerpSpeed); + } + + //Check if Exp bar is full + if (expBarSprite.fillAmount >= 1.0f) { LevelUp(); clicksNeeded = (expRequired - expObtained) / Increment; - barPosition = 0; - this.gameObject.GetComponent().sizeDelta = new Vector3(barPosition, barHeight); + fillAmount = 0; } } public void ExpMore() { + ++clicks; expObtained = expObtained + Increment; - //Since increment is 10 && Level 1 = 100 - //10 clicks per level DIVDED BY clicks required for exp gain - //int clicks = 0; - //clicks++; - barMovement = (barWidth / clicksNeeded) / 10.0f ; - barPosition = barMovement + barPosition; - Debug.Log("barPosition = " + barPosition); - //use time.deltatime to smooth this out to make it look better? - this.gameObject.GetComponent().sizeDelta = new Vector3(barPosition * 10, barHeight); + fillAmount = (expObtained / expRequired); + Debug.Log("fillAmount = " + fillAmount); } public void LevelUp() { - level++; + ++level; levelText.GetComponent().text = level.ToString(); - expRequired = Mathf.Pow(expRequired, 1.05f) + expRequired ; + previousExpRequired = expRequired; + expObtained = 0; + expRequired = Mathf.Pow(expRequired, 1.05f); } public void ResetExp() { - barPosition = 0; - this.gameObject.GetComponent().sizeDelta = new Vector3(barPosition, barHeight); - expObtained = 0; level = 1; levelText.GetComponent().text = level.ToString(); + fillAmount = 0; + expObtained = 0; expRequired = 100; clicksNeeded = 10; + clicks = 0; } public void ExpLess() { + --clicks; expObtained = expObtained - Increment; - //Since increment is 10 && Level 1 = 100 - //10 clicks per level DIVDED BY clicks required for exp gain - //int clicks = 0; - //clicks++; - barMovement = (barWidth / clicksNeeded) / 10.0f; - barPosition = barPosition - barMovement; - Debug.Log("barPosition = " + barPosition); - //use time.deltatime to smooth this out to make it look better? - this.gameObject.GetComponent().sizeDelta = new Vector3(barPosition * 10, barHeight); + fillAmount = (expObtained / expRequired); + Debug.Log("fillAmount = " + fillAmount); } }