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 {
|
|
|
|
|
// Eventually.. public RectTransform gainedExp
|
|
|
|
|
//Array used as expRequired[leveldesired]
|
2017-08-26 22:31:01 +00:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private int level = 1;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float expObtained = 0;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float expRequired = 100;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float fillAmount;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject levelText;
|
|
|
|
|
[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-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = 0;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update () {
|
|
|
|
|
|
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();
|
|
|
|
|
clicksNeeded = (expRequired - expObtained) / 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-08-23 15:11:04 +00:00
|
|
|
|
expObtained = expObtained + Increment;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = (expObtained / expRequired);
|
|
|
|
|
Debug.Log("fillAmount = " + fillAmount);
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LevelUp()
|
|
|
|
|
{
|
2017-08-26 22:31:01 +00:00
|
|
|
|
++level;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
levelText.GetComponent<Text>().text = level.ToString();
|
2017-08-26 22:31:01 +00:00
|
|
|
|
previousExpRequired = expRequired;
|
|
|
|
|
expObtained = 0;
|
|
|
|
|
expRequired = Mathf.Pow(expRequired, 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()
|
|
|
|
|
{
|
|
|
|
|
level = 1;
|
|
|
|
|
levelText.GetComponent<Text>().text = level.ToString();
|
2017-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = 0;
|
|
|
|
|
expObtained = 0;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
expRequired = 100;
|
|
|
|
|
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-08-23 15:11:04 +00:00
|
|
|
|
expObtained = expObtained - Increment;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
fillAmount = (expObtained / expRequired);
|
|
|
|
|
Debug.Log("fillAmount = " + fillAmount);
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
|
|
|
|
}
|