I have tried to set a variable in a script two different ways however I still get the same issue for both telling me that “initializer cannot reference the monostatic field, method etc.”
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Health : MonoBehaviour
{
public Text text;
public int PHealth = 4;
void start()
{
if (text.text) text.text = PHealth.ToString(); //assign health value to text
}
}
public class Health : MonoBehaviour
{
public Text text;
public int PHealth = 4;
GameObject CHealth = GameObject.Find("Health"); // get reference for health
Health Chealth = CHealth.GetComponent<Health>();
void start()
{
if (text.text) text.text = PHealth.ToString(); //assign health value to text
}
}
the text has been set to the Health text in the inspector.
thank you it helped but now I get an error stating that it cannot implicitly convert ‘string’ to ‘bool’ which has lost me completely.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Health : MonoBehaviour
{
public Text health;
public int PHealth = 4;
//GameObject CHealth = GameObject.Find("Health"); // get reference for health
//Health Chealth = CHealth.GetComponent<Health>();
void start()
{
if (health.text) health.text = PHealth.ToString(); //assign health value to text
}
}