I’m just starting unity and making a card game. I have a Quad GameObject “CardQuad” with a bunch of child objects, some of which are TextMesh objects that will represent the card name, abilities, health, and attack of the card. I am trying to set the TextMesh in Update(). I can set it to a quoted string, but when I try to set it to a string variable it comes out as blank when I hit play.
I’ve set my public variables in the UI.
Debug.Log shows:
"Rampaging Rhino of the Jungle
UnityEngine.Debug:Log(Object)
CardCreator:Start() (at Assets/CardCreator.cs:19)"
So I know my string assign is working.
Why is it not setting the TextMesh.text to my variable though?
using UnityEngine;
using System.Collections;
public class CardCreator : MonoBehaviour {
public string prefix;
public string suffix;
public string creatureType;
public int attack;
public int defense;
public string abilities;
public char color;
string cardName;
// Use this for initialization
void Start () {
cardName = prefix + " " + creatureType + " " + suffix;
Debug.Log (cardName);
}
// Update is called once per frame
void Update () {
GameObject g = GameObject.FindGameObjectWithTag ("CardName");
TextMesh t = g.GetComponent<TextMesh> ();
Debug.Log ("Name = '" + t.text + "'");
t.text = "some new string"; //this works and updates the card name
t.text = cardName; //this makes the card name blank
}
}
