I'm having an error
CS0029, Can not implicitly convert type
int' to
UnityEngine.UI.Slider '
How can I resolve it?
First Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerStats : MonoBehaviour {
public static int Level = 1;
public static int nextLevel;
public static int xp = 0;
public static int xpToLevel;
public static int xpDiff;
public static int life;
public static int totalLife;
public static int magic;
public static int totalMagic;
public static int attack;
public static int defense;
// Use this for initialization
void Start () {
recauculation ();
}
// Update is called once per frame
void Update () {
nextLevel = Level + 1;
xpToLevel = 50 * nextLevel * Level;
if (xp >= xpToLevel) {
xpDiff = xp - xpToLevel;
LevelUp ();
}
attack = 5 * Level;
defense = 3 * Level;
if (Input.GetKeyDown (KeyCode.Q)) {
AddXp (125);
}
}
public void recauculation (){
totalLife = 25 * Level;
totalMagic = 10 * Level;
life = totalLife;
magic = totalMagic;
}
public void AddXp (int newXp) {
xp += newXp;
}
public void LevelUp () {
Level++;
xp = 0 + xpDiff;
recauculation ();
}
}
Second Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Hud : MonoBehaviour {
public Text LevelText;
public Slider lifeSlider;
public Slider magicSlider;
public Slider xpSlider;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
LevelText.text = PlayerStats.Level.ToString ();
lifeSlider = PlayerStats.totalLife;
lifeSlider = PlayerStats.life;
magicSlider = PlayerStats.totalMagic;
magicSlider = PlayerStats.magic;
xpSlider = PlayerStats.xpToLevel;
xpSlider = PlayerStats.xp;
}
}