Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class XP_Login : MonoBehaviour
- {
- // Start is called before the first frame update
- int level;
- int xp;
- public string url = DBManager.GetBaseURL() + "updateXP.php?username=" + DBManager.username;
- public int vLevel = DBManager.level;
- public int vCurrExp = DBManager.xp;
- public int vExpBase = 4;
- public int vExpLeft = DBManager.level;
- public float vExpMod = 1.15f;
- public int expUpMount = 4;
- public Text text_lev;
- public Slider slider_ex;
- void Start()
- {
- slider_ex.value = vCurrExp;
- slider_ex.maxValue = vExpLeft;
- text_lev.text = vLevel.ToString();
- }
- // Update is called once per frame
- void Update()
- {
- slider_ex.value = vCurrExp;
- }
- public void pushData()
- {
- StartCoroutine(Upload());
- }
- public void GainExp(int e)
- {
- vCurrExp += e;
- if (vCurrExp >= vExpLeft)
- {
- LvlUp();
- text_lev.text = vLevel.ToString();
- slider_ex.maxValue = vExpLeft;
- }
- pushData();
- }
- void LvlUp()
- {
- vCurrExp -= vExpLeft;
- vLevel++;
- float t = Mathf.Pow(vExpMod, vLevel);
- // vExpLeft = (int)vExpLeft * vExpLeft * 2;
- //vExpLeft = (int)Mathf.Floor(vExpBase * t);
- vExpLeft = (int)vExpLeft * 2;
- }
- IEnumerator Upload()
- {
- WWWForm form = new WWWForm();
- form.AddField("level", vLevel);
- form.AddField("xp", vCurrExp);
- UnityWebRequest www = UnityWebRequest.Post(DBManager.GetBaseURL() + "updateXP.php?username=" + DBManager.username, form);
- yield return www.SendWebRequest();
- if (www.isNetworkError || www.isHttpError)
- {
- Debug.Log(www.error);
- }
- else
- {
- Debug.Log("Form upload complete!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement