2017-08-22 17:29:01 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
2017-08-23 15:11:04 +00:00
|
|
|
|
public class ExperienceBar : MonoBehaviour {
|
2017-08-26 22:31:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
//Playerdata -- Needs saved
|
2017-09-03 22:56:05 +00:00
|
|
|
|
public int currentLevel = 1;
|
|
|
|
|
public float currentExp = 0;
|
|
|
|
|
public float currentRequirement = 100;
|
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject currentLevelText;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private float fillAmount;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Image expBarSprite;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float lerpSpeed;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private int clicks;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
|
2017-08-26 22:31:01 +00:00
|
|
|
|
private float clicksNeeded = 10;
|
|
|
|
|
private float previousExpRequired;
|
|
|
|
|
private float barMovement;
|
|
|
|
|
private float barPosition;
|
|
|
|
|
private float Increment = 10;
|
|
|
|
|
|
2017-08-23 15:11:04 +00:00
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start () {
|
2017-09-03 22:56:05 +00:00
|
|
|
|
fillAmount = currentExp / currentRequirement;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update () {
|
2017-09-03 22:56:05 +00:00
|
|
|
|
fillAmount = currentExp / currentRequirement;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLevelText.GetComponent<Text>().text != currentLevel.ToString()){
|
|
|
|
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
|
|
|
|
}
|
2017-08-23 15:11:04 +00:00
|
|
|
|
|
2017-08-26 22:31:01 +00:00
|
|
|
|
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)
|
2017-08-22 17:29:01 +00:00
|
|
|
|
{
|
2017-08-23 15:11:04 +00:00
|
|
|
|
LevelUp();
|
2017-09-03 22:56:05 +00:00
|
|
|
|
clicksNeeded = (currentRequirement - currentExp) / Increment;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = 0;
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExpMore()
|
|
|
|
|
{
|
2017-08-26 22:31:01 +00:00
|
|
|
|
++clicks;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentExp = currentExp + Increment;
|
|
|
|
|
fillAmount = currentExp / currentRequirement;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
Debug.Log("fillAmount = " + fillAmount);
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LevelUp()
|
|
|
|
|
{
|
2017-09-03 22:56:05 +00:00
|
|
|
|
++currentLevel;
|
|
|
|
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
|
|
|
|
previousExpRequired = currentRequirement;
|
|
|
|
|
currentExp = 0;
|
|
|
|
|
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
|
2017-09-03 19:58:42 +00:00
|
|
|
|
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed();
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetExp()
|
|
|
|
|
{
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentLevel = 1;
|
|
|
|
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
2017-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = 0;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentExp = 0;
|
|
|
|
|
currentRequirement = 100;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
clicksNeeded = 10;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
clicks = 0;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExpLess()
|
|
|
|
|
{
|
2017-08-26 22:31:01 +00:00
|
|
|
|
--clicks;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentExp = currentExp - Increment;
|
|
|
|
|
fillAmount = (currentExp / currentRequirement);
|
2017-08-26 22:31:01 +00:00
|
|
|
|
Debug.Log("fillAmount = " + fillAmount);
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 22:56:05 +00:00
|
|
|
|
public float GetExperience()
|
|
|
|
|
{
|
|
|
|
|
float currentExp;
|
|
|
|
|
currentExp = this.currentExp;
|
|
|
|
|
return currentExp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|