Hello,
I hope I am posting in the correct thread. I am a game artist who has recently begun learning C# to make games in Unity. I feel like I am misunderstanding what needs to be done in order to get a script to change the text to the information stored in another script. The goal is to display what the current enemy health is on the screen, but I would like it to pull the info from an enemy controller script. Here is the code for both the health display and the enemy controller so far:
EnemyHealth.cs
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class EnemyHealth : MonoBehaviour {
Text enemyHealthText;
// Use this for initialization
void Start () {
// Establish enemyHealthTExt as the Text in this object
enemyHealthText = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
}
void EnemyHealthDisplay () {
// Grab the EnemyController script variables
GameObject enemyController = GameObject.Find("Enemy Controller");
EnemyController enemyControllerScript = enemyController.GetComponent<EnemyController>();
// Show the enemy health
enemyHealthText.text = enemyControllerScript.enemyHealth.ToString ();
}
}
EnemyController.cs
using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour {
public float enemyHealth;
// Use this for initialization
void Start () {
enemyHealth = 12.0f;
}
// Update is called once per frame
void Update () {
}
}
Any help would be tremendously appreciated. I am still struggling with understanding most of the structure so any educational links or threads on similar code would rock as well.