Fixed ExperienceBar.cs
Fixed bar filling up before gaining require exp Added exp curve (required + required^1.05) Removed fixed levels, added infinite progression Fixed clicksNeeded to account for expObtained Added ExpReset() and ExpLess() Needs: Click count Better debug logs Delevel if previousExpRequired>expObtained ( When using ExpLess() ) --Exponential equation to determine infinite previous levels without storing them individually?
This commit is contained in:
		
							parent
							
								
									ebac7507ef
								
							
						
					
					
						commit
						3251ae85b6
					
				| @ -2,12 +2,12 @@ | |||||||
| using System.Collections; | using System.Collections; | ||||||
| using UnityEngine.UI; | using UnityEngine.UI; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| public class ExperienceBar : MonoBehaviour { | public class ExperienceBar : MonoBehaviour { | ||||||
| 
 | 
 | ||||||
|     public int Exp = 0; |   public float expObtained = 0; | ||||||
|     public string level = "1"; |   public int level = 0; | ||||||
|     public int nextLevel = 1; |   public float Increment = 10; | ||||||
|     public int Increment = 10; |  | ||||||
|   public GameObject levelText; |   public GameObject levelText; | ||||||
|   public float barWidth; |   public float barWidth; | ||||||
|   public float barHeight; |   public float barHeight; | ||||||
| @ -15,7 +15,7 @@ public class ExperienceBar : MonoBehaviour { | |||||||
|   GameObject expBar; |   GameObject expBar; | ||||||
|   // Eventually.. public RectTransform gainedExp |   // Eventually.. public RectTransform gainedExp | ||||||
|   //Array used as expRequired[leveldesired] |   //Array used as expRequired[leveldesired] | ||||||
|     public int[] expRequired = {0,0,100,250,450,700,1000,1350,1700,2150,2650 }; |   public float expRequired = 100; | ||||||
|   public float clicksNeeded = 10; |   public float clicksNeeded = 10; | ||||||
|   float barMovement; |   float barMovement; | ||||||
|   float barPosition; |   float barPosition; | ||||||
| @ -23,95 +23,67 @@ public class ExperienceBar : MonoBehaviour { | |||||||
|   // Use this for initialization |   // Use this for initialization | ||||||
|   void Start () { |   void Start () { | ||||||
|     expBar = this.gameObject; |     expBar = this.gameObject; | ||||||
|  |     barPosition = 0; | ||||||
|  |     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Update is called once per frame |   // Update is called once per frame | ||||||
|   void Update () { |   void Update () { | ||||||
|         checkExpGain(); |  | ||||||
|     //Check if Exp bar is full |     //Check if Exp bar is full | ||||||
| 
 | 
 | ||||||
|     if(this.gameObject.GetComponent<RectTransform>().sizeDelta.x == barWidth || expBar.GetComponent<RectTransform>().sizeDelta.x > barWidth) |     if(this.gameObject.GetComponent<RectTransform>().sizeDelta.x == barWidth || expBar.GetComponent<RectTransform>().sizeDelta.x > barWidth) | ||||||
|     { |     { | ||||||
|             this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(0, barHeight); |       LevelUp(); | ||||||
|  |       clicksNeeded = (expRequired - expObtained) / Increment; | ||||||
|       barPosition = 0; |       barPosition = 0; | ||||||
|             levelText.GetComponent<Text>().text = level; |       this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|     public void ExpGain() |   public void ExpMore() | ||||||
|   { |   { | ||||||
|         Exp = Exp + Increment; |     expObtained = expObtained + Increment; | ||||||
|  |     //Since increment is 10 && Level 1 = 100 | ||||||
|     //10 clicks per level DIVDED BY clicks required for exp gain |     //10 clicks per level DIVDED BY clicks required for exp gain | ||||||
|         barMovement = 10 / clicksNeeded; |     //int clicks = 0; | ||||||
|  |     //clicks++; | ||||||
|  |     barMovement = (barWidth / clicksNeeded) / 10.0f ;  | ||||||
|     barPosition = barMovement + barPosition; |     barPosition = barMovement + barPosition; | ||||||
|     Debug.Log("barPosition = " + barPosition); |     Debug.Log("barPosition = " + barPosition); | ||||||
|     //use time.deltatime to smooth this out to make it look better? |     //use time.deltatime to smooth this out to make it look better? | ||||||
|     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition * 10, barHeight);  |     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition * 10, barHeight);  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 |   public void LevelUp() | ||||||
|     public void checkExpGain() |  | ||||||
|   { |   { | ||||||
|         switch(Exp) |     level++; | ||||||
|  |     levelText.GetComponent<Text>().text = level.ToString(); | ||||||
|  |     expRequired = Mathf.Pow(expRequired, 1.05f) + expRequired ; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public void ResetExp() | ||||||
|   { |   { | ||||||
|             case (100): |     barPosition = 0; | ||||||
|                 level = "2"; |     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||||
|                 nextLevel = 3; |     expObtained = 0; | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp)/10; |     level = 1; | ||||||
|                 break; |     levelText.GetComponent<Text>().text = level.ToString(); | ||||||
| 
 |     expRequired = 100; | ||||||
| 
 |     clicksNeeded = 10; | ||||||
|             case (250): |   } | ||||||
|                 level = "3"; |  | ||||||
|                 nextLevel = 4; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
| 
 |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (450): |  | ||||||
|                 level = "4"; |  | ||||||
|                 nextLevel = 5; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
| 
 |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (700): |  | ||||||
|                 level = "5"; |  | ||||||
|                 nextLevel = 6; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (1000): |  | ||||||
|                 level = "6"; |  | ||||||
|                 nextLevel = 7; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (1350): |  | ||||||
|                 level = "7"; |  | ||||||
|                 nextLevel = 8; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (1700): |  | ||||||
|                 level = "8"; |  | ||||||
|                 nextLevel = 9; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (2150): |  | ||||||
|                 level = "9"; |  | ||||||
|                 nextLevel = 10; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 |  | ||||||
|             case (2650): |  | ||||||
|                 level = "10"; |  | ||||||
|                // nextLevel = 10; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |  | ||||||
|                 break; |  | ||||||
| 
 | 
 | ||||||
|  |   public void ExpLess() | ||||||
|  |   { | ||||||
|  |     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<RectTransform>().sizeDelta = new Vector3(barPosition * 10, barHeight); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user