Advertisement
Guest User

Untitled

a guest
May 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6. public class XP_Login : MonoBehaviour
  7. {
  8.     // Start is called before the first frame update
  9.     int level;
  10.     int xp;
  11.     public string url = DBManager.GetBaseURL() + "updateXP.php?username=" + DBManager.username;
  12.  
  13.  
  14.     public int vLevel = DBManager.level;
  15.     public int vCurrExp = DBManager.xp;
  16.     public int vExpBase = 4;
  17.     public int vExpLeft = DBManager.level;
  18.     public float vExpMod = 1.15f;
  19.     public int expUpMount = 4;
  20.  
  21.     public Text text_lev;
  22.     public Slider slider_ex;
  23.     void Start()
  24.     {
  25.         slider_ex.value = vCurrExp;
  26.         slider_ex.maxValue = vExpLeft;
  27.         text_lev.text = vLevel.ToString();
  28.     }
  29.  
  30.     // Update is called once per frame
  31.     void Update()
  32.     {
  33.  
  34.  
  35.  
  36.  
  37.         slider_ex.value = vCurrExp;
  38.     }
  39.  
  40.  
  41.     public void pushData()
  42.     {
  43.         StartCoroutine(Upload());
  44.  
  45.     }
  46.  
  47.     public void GainExp(int e)
  48.     {
  49.  
  50.         vCurrExp += e;
  51.  
  52.         if (vCurrExp >= vExpLeft)
  53.         {
  54.             LvlUp();
  55.             text_lev.text = vLevel.ToString();
  56.             slider_ex.maxValue = vExpLeft;
  57.  
  58.         }
  59.         pushData();
  60.     }
  61.     void LvlUp()
  62.     {
  63.         vCurrExp -= vExpLeft;
  64.         vLevel++;
  65.         float t = Mathf.Pow(vExpMod, vLevel);
  66.         // vExpLeft = (int)vExpLeft * vExpLeft * 2;
  67.  
  68.         //vExpLeft = (int)Mathf.Floor(vExpBase * t);
  69.         vExpLeft = (int)vExpLeft * 2;
  70.     }
  71.  
  72.     IEnumerator Upload()
  73.     {
  74.         WWWForm form = new WWWForm();
  75.         form.AddField("level", vLevel);
  76.         form.AddField("xp", vCurrExp);
  77.         UnityWebRequest www = UnityWebRequest.Post(DBManager.GetBaseURL() + "updateXP.php?username=" + DBManager.username, form);
  78.         yield return www.SendWebRequest();
  79.  
  80.         if (www.isNetworkError || www.isHttpError)
  81.         {
  82.             Debug.Log(www.error);
  83.         }
  84.         else
  85.         {
  86.             Debug.Log("Form upload complete!");
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement