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 UnityEngine.UI; | ||||
| 
 | ||||
| 
 | ||||
| public class ExperienceBar : MonoBehaviour { | ||||
| 
 | ||||
|     public int Exp = 0; | ||||
|     public string level = "1"; | ||||
|     public int nextLevel = 1; | ||||
|     public int Increment = 10; | ||||
|   public float expObtained = 0; | ||||
|   public int level = 0; | ||||
|   public float Increment = 10; | ||||
|   public GameObject levelText; | ||||
|   public float barWidth; | ||||
|   public float barHeight; | ||||
| @ -15,7 +15,7 @@ public class ExperienceBar : MonoBehaviour { | ||||
|   GameObject expBar; | ||||
|   // Eventually.. public RectTransform gainedExp | ||||
|   //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; | ||||
|   float barMovement; | ||||
|   float barPosition; | ||||
| @ -23,95 +23,67 @@ public class ExperienceBar : MonoBehaviour { | ||||
|   // Use this for initialization | ||||
|   void Start () { | ||||
|     expBar = this.gameObject; | ||||
|     barPosition = 0; | ||||
|     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||
|   } | ||||
| 
 | ||||
|   // Update is called once per frame | ||||
|   void Update () { | ||||
|         checkExpGain(); | ||||
|     //Check if Exp bar is full | ||||
| 
 | ||||
|     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; | ||||
|             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 | ||||
|         barMovement = 10 / clicksNeeded; | ||||
|     //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<RectTransform>().sizeDelta = new Vector3(barPosition * 10, barHeight);  | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|     public void checkExpGain() | ||||
|   public void LevelUp() | ||||
|   { | ||||
|         switch(Exp) | ||||
|     level++; | ||||
|     levelText.GetComponent<Text>().text = level.ToString(); | ||||
|     expRequired = Mathf.Pow(expRequired, 1.05f) + expRequired ; | ||||
|   } | ||||
| 
 | ||||
|   public void ResetExp() | ||||
|   { | ||||
|             case (100): | ||||
|                 level = "2"; | ||||
|                 nextLevel = 3; | ||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp)/10; | ||||
|                 break; | ||||
| 
 | ||||
| 
 | ||||
|             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; | ||||
| 
 | ||||
| 
 | ||||
|     barPosition = 0; | ||||
|     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||
|     expObtained = 0; | ||||
|     level = 1; | ||||
|     levelText.GetComponent<Text>().text = level.ToString(); | ||||
|     expRequired = 100; | ||||
|     clicksNeeded = 10; | ||||
|   } | ||||
| 
 | ||||
|   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