- Home /
Unity 4.6 adding a Canvas Text onto a gameobject prefab??
A bit confusing to explain but im using a script that auto updates text on my canvas. The scripts is attached to a gameobject prefab. I cant drag the text onto the gameprefab when its not on the scene but when i add the prefab onto the scene i am able to drag the text onto the prefab inside the scene. Any ideas what how to get around this?
using UnityEngine;
using System.Collections;
**using UnityEngine.UI;**
public class EnemyHealthScriptCOPY : MonoBehaviour
{
/// <summary>
/// Total hitpoints
/// </summary>
public int Sp = 0;
private int Hp = 1;
public bool isEnemy = true;
**public Text ScoreText;**
void OnTriggerEnter2D(Collider2D collider)
{
// Is this a shot?
ShotScript shot = collider.gameObject.GetComponent<ShotScript>();
if (shot != null)
{
// Avoid friendly fire
if (shot.isEnemyShot != isEnemy)
{
Hp -= shot.damage;
// // Destroy the shot
// // Remember to always target the game object,
// // otherwise you will just remove the script.
Destroy(shot.gameObject);
Sp += shot.damage;
//scoreText.text = ("Score: " + Sp);//display in my text3d "Score: plus whatever number mySore is on
**ScoreText.text = ("Score: " + Sp);**
if (Hp <= 0)
{
SpecialEffectsHelper.Instance.Explosion(transform.position);
SoundEffectsHelper.Instance.MakeExplosionSound();
Destroy(gameObject);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
UI Text Component being reset on player when built 0 Answers
Use Unity UI For 2D Games Or Custom Objects Instead? 2 Answers
How to change Normal color, Highlighted color etc. in 4.6 buttons with code 2 Answers
[4.6 GUI] Displaying my pause menu when ESC is pressed 2 Answers
UI canvas appearing smaller on build. 0 Answers