Skip to main content
added 117 characters in body
Source Link
BonnieB
  • 101
  • 2
  • 10

My Slider GameObject has a GUIText child. I am writing a C# script that should change the text component in the GUIText, but instead of this I am getting:

error CS1061: Type UnityEngine.GUIText[]' does not contain a definition for text' and no extension method text' of type UnityEngine.GUIText[]' could be found (are you missing a using directive or an assembly reference?)

 public Slider timeSlider;
 int i = 5;

 timeSlider.GetComponentsInChildren<GUIText>().text = 'Some Text' + i;
 //timeSlider.transform.GetComponentsInChildren<GUIText>().text = 'Some Text' + i; // doesn't work either

From the documentation I understand that GUIText should have a 'text' variable - Would anyone know why ().text is invalid?

Thank you!

How the hierachy is:

enter image description here

My Slider GameObject has a GUIText child. I am writing a C# script that should change the text component in the GUIText, but instead of this I am getting:

error CS1061: Type UnityEngine.GUIText[]' does not contain a definition for text' and no extension method text' of type UnityEngine.GUIText[]' could be found (are you missing a using directive or an assembly reference?)

 public Slider timeSlider;
 int i = 5;

 timeSlider.GetComponentsInChildren<GUIText>().text = 'Some Text' + i;
 //timeSlider.transform.GetComponentsInChildren<GUIText>().text = 'Some Text' + i; // doesn't work either

From the documentation I understand that GUIText should have a 'text' variable - Would anyone know why ().text is invalid?

Thank you!

My Slider GameObject has a GUIText child. I am writing a C# script that should change the text component in the GUIText, but instead of this I am getting:

error CS1061: Type UnityEngine.GUIText[]' does not contain a definition for text' and no extension method text' of type UnityEngine.GUIText[]' could be found (are you missing a using directive or an assembly reference?)

 public Slider timeSlider;
 int i = 5;

 timeSlider.GetComponentsInChildren<GUIText>().text = 'Some Text' + i;
 //timeSlider.transform.GetComponentsInChildren<GUIText>().text = 'Some Text' + i; // doesn't work either

From the documentation I understand that GUIText should have a 'text' variable - Would anyone know why ().text is invalid?

Thank you!

How the hierachy is:

enter image description here

Source Link
BonnieB
  • 101
  • 2
  • 10

GetComponentsInChildren<GUIText>().text - does not contain a definition

My Slider GameObject has a GUIText child. I am writing a C# script that should change the text component in the GUIText, but instead of this I am getting:

error CS1061: Type UnityEngine.GUIText[]' does not contain a definition for text' and no extension method text' of type UnityEngine.GUIText[]' could be found (are you missing a using directive or an assembly reference?)

 public Slider timeSlider;
 int i = 5;

 timeSlider.GetComponentsInChildren<GUIText>().text = 'Some Text' + i;
 //timeSlider.transform.GetComponentsInChildren<GUIText>().text = 'Some Text' + i; // doesn't work either

From the documentation I understand that GUIText should have a 'text' variable - Would anyone know why ().text is invalid?

Thank you!