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,116 +2,88 @@ | |||||||
| 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; |      | ||||||
|  |   GameObject expBar; | ||||||
|  |   // Eventually.. public RectTransform gainedExp | ||||||
|  |   //Array used as expRequired[leveldesired] | ||||||
|  |   public float expRequired = 100; | ||||||
|  |   public float clicksNeeded = 10; | ||||||
|  |   float barMovement; | ||||||
|  |   float barPosition; | ||||||
|  |      | ||||||
|  |   // Use this for initialization | ||||||
|  |   void Start () { | ||||||
|  |     expBar = this.gameObject; | ||||||
|  |     barPosition = 0; | ||||||
|  |     this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|     GameObject expBar; |   // Update is called once per frame | ||||||
|     // Eventually.. public RectTransform gainedExp |   void Update () { | ||||||
|     //Array used as expRequired[leveldesired] |     //Check if Exp bar is full | ||||||
|     public int[] expRequired = {0,0,100,250,450,700,1000,1350,1700,2150,2650 }; |  | ||||||
|     public float clicksNeeded = 10; |  | ||||||
|     float barMovement; |  | ||||||
|     float barPosition; |  | ||||||
| 
 | 
 | ||||||
|     // Use this for initialization |     if(this.gameObject.GetComponent<RectTransform>().sizeDelta.x == barWidth || expBar.GetComponent<RectTransform>().sizeDelta.x > barWidth) | ||||||
|     void Start () { |  | ||||||
|         expBar = this.gameObject; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	// 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); |  | ||||||
|             barPosition = 0; |  | ||||||
|             levelText.GetComponent<Text>().text = level; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void ExpGain() |  | ||||||
|     { |     { | ||||||
|         Exp = Exp + Increment; |       LevelUp(); | ||||||
|         //10 clicks per level DIVDED BY clicks required for exp gain |       clicksNeeded = (expRequired - expObtained) / Increment; | ||||||
|         barMovement = 10 / clicksNeeded; |       barPosition = 0; | ||||||
|         barPosition = barMovement + barPosition; |       this.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(barPosition, barHeight); | ||||||
|         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 ExpMore() | ||||||
|  |   { | ||||||
|  |     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<RectTransform>().sizeDelta = new Vector3(barPosition * 10, barHeight);  | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|     public void checkExpGain() |   public void LevelUp() | ||||||
|     { |   { | ||||||
|         switch(Exp) |     level++; | ||||||
|         { |     levelText.GetComponent<Text>().text = level.ToString(); | ||||||
|             case (100): |     expRequired = Mathf.Pow(expRequired, 1.05f) + expRequired ; | ||||||
|                 level = "2"; |   } | ||||||
|                 nextLevel = 3; |  | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp)/10; |  | ||||||
|                 break; |  | ||||||
| 
 | 
 | ||||||
|  |   public void ResetExp() | ||||||
|  |   { | ||||||
|  |     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; | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|             case (250): |   public void ExpLess() | ||||||
|                 level = "3"; |   { | ||||||
|                 nextLevel = 4; |     expObtained = expObtained - Increment; | ||||||
|                 clicksNeeded = (expRequired[nextLevel] - Exp) / 10; |     //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); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|                 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; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user