TheTar
Can someone Help me understand why my Mana code is not working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerStats : MonoBehaviour
public Slider pManaBar;
public float pMana;
public float pMaxMana = 100;
void RegenerateMana()
{
IceBall ice = gameObject.GetComponent<IceBall>();
if (ice != null)
{
if (pMana < pMaxMana & !ice.usingMana)
{
pMana += pManaRegen * Time.deltaTime;
if (pMana > pMaxMana) pMana = pMaxMana;
UpdateUI();
Debug.Log("UsingMANA");
}
}
}
public void UseMana(float amount)
{
pMana -= amount;
UpdateUI();
if (pMana < 0) pMana = 0;
Debug.Log("UseMana");
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class IceBall : MonoBehaviour
{
public float manaIce = 50;
public bool usingMana = false;
private void OnTriggerEnter2D(Collider2D collision)
{
PlayerStats stats = collision.gameObject.GetComponent<PlayerStats>();
if (stats != null)
{ Debug.Log("What stats", null); stats.UseMana(manaIce * Time.deltaTime); usingMana = true; } else { usingMana = false; } } }
{ Debug.Log("What stats", null); stats.UseMana(manaIce * Time.deltaTime); usingMana = true; } else { usingMana = false; } } }
22 replies