using UnityEngine;
using System.Collections;
public class practicescript : MonoBehaviour
{
public class Health
{
float MaxHealth = 100f;
float CurrHealth = 100f;
float Regeneration = .01f;
public Health(){
MaxHealth = 100;
CurrHealth = 100;
Regeneration = .01;
}
}
void Start () {
Health Myhealth = new Health()
{
CurrHealth = MaxHealth
}
}
void Update () {
if (CurrHealth < 100f)
{
CurrHealth += Regeneration*Time.deltaTime;
}
}
}
1 Answer
1
first create variable of Health type in practicescript. Create object in Start. Use dot operator in Update to access CurrHealth variable.
using UnityEngine; using System.Collections;
public class practicescript : MonoBehaviour
{
public class Health {
float MaxHealth = 100f;
float CurrHealth = 100f;
float Regeneration = .01f;
public Health(){
MaxHealth = 100;
CurrHealth = 100;
Regeneration = .01;
}
}
Health MyHealth = null;
void Start () {
Myhealth = new Health();
}
void Update () {
if (MyHealth.CurrHealth < 100f)
{
MyHealth.CurrHealth += MyHealth.Regeneration*Time.deltaTime;
}
}
}