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-09-05 22:12:08 +00:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject eventSystem;
|
|
|
|
|
|
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;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
[SerializeField]
|
|
|
|
|
public float expIncrement = 10.0f;
|
2017-09-05 22:12:08 +00:00
|
|
|
|
private string notify;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
|
2017-08-23 15:11:04 +00:00
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start () {
|
2017-09-05 22:12:08 +00:00
|
|
|
|
eventSystem = GameObject.Find("EventSystem");
|
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;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
this.gameObject.GetComponentInChildren<Text>().text = (int)currentExp + " / " + (int)currentRequirement;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
|
|
|
|
|
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-06 01:41:56 +00:00
|
|
|
|
clicksNeeded = (currentRequirement - currentExp) / expIncrement;
|
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-06 01:41:56 +00:00
|
|
|
|
currentExp = currentExp + expIncrement;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
fillAmount = currentExp / currentRequirement;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
notify = "+" + expIncrement + "EXP";
|
|
|
|
|
eventSystem.GetComponent<GameManager>().RewardPopup(expIncrement, 1);
|
2017-09-05 22:12:08 +00:00
|
|
|
|
|
2017-09-04 23:53:18 +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;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
expIncrement += 10;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
|
|
|
|
previousExpRequired = currentRequirement;
|
2017-09-04 19:30:19 +00:00
|
|
|
|
currentExp -= previousExpRequired;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
|
2017-09-03 19:58:42 +00:00
|
|
|
|
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed();
|
2017-09-06 01:41:56 +00:00
|
|
|
|
notify = "Level " + currentLevel + "!";
|
|
|
|
|
eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2);
|
|
|
|
|
|
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();
|
|
|
|
|
currentExp = 0;
|
2017-09-04 19:30:19 +00:00
|
|
|
|
fillAmount = 0;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
expIncrement = 10.0f;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
currentRequirement = 100;
|
2017-08-23 15:11:04 +00:00
|
|
|
|
clicksNeeded = 10;
|
2017-08-26 22:31:01 +00:00
|
|
|
|
clicks = 0;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
notify = "EXP Reset";
|
|
|
|
|
eventSystem.GetComponent<GameManager>().MakeStringPopup(notify, 1);
|
|
|
|
|
|
2017-08-23 15:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExpLess()
|
|
|
|
|
{
|
2017-08-26 22:31:01 +00:00
|
|
|
|
--clicks;
|
2017-09-06 01:41:56 +00:00
|
|
|
|
currentExp = currentExp - expIncrement;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
fillAmount = (currentExp / currentRequirement);
|
2017-08-26 22:31:01 +00:00
|
|
|
|
Debug.Log("fillAmount = " + fillAmount);
|
2017-09-06 01:41:56 +00:00
|
|
|
|
notify = "-" + expIncrement + "EXP";
|
|
|
|
|
eventSystem.GetComponent<GameManager>().RewardPopup(-expIncrement, 1);
|
|
|
|
|
|
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
|
|
|
|
}
|