- Home /
Question by
connorwforman · Mar 08, 2018 at 11:04 PM ·
scripting problemerrorgameobjecttextstring
Text component change through script not working
I have this set up in a way I think it should work but it keeps saying ": Cannot implicitly convert type 'string' to 'UnityEngine.GameObject'"
using UnityEngine.UI;
public GameObject Bs_In_Gun;
public float bullets;
public float MaxBullets;
void Start () {
bullets = MaxBullets;
Bs_In_Gun = GetComponent<Text> ().text = "" + bullets;
}
Comment
Best Answer
Answer by Rygaran · Mar 08, 2018 at 11:21 PM
you're assinning Bs_In_Gun, which is a game object, the string located in GetComponent ().text, and also the string of "" + bullets. You need to remove the first part and just leave it as GetComponent ().text = "" + bullets;. In case you were trying to get the text component in Bs_In_Gun, you need to write it like this: Bs_In_Gun.GetComponent ().text = "" + bullets; Not "=" but "."