Question by
zak666 · Nov 13, 2016 at 03:17 PM ·
textgameobject.find
Trying to FindgameObject with tag and then edit its text. error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
Seems you cannot user .text or get component Text to assign the text when you use GameObject .find, how do you access the text component using Gameobject.find?
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
public GameObject MissileCountText;
public GameObject SpecialWeapon;
public bool IsLockedOnBool;
public bool Activate = false;
public int MissileCount = 5;
[NetSync]
public bool FireMissile;
public void Start(){
MissileCountText = GameObject.FindGameObjectWithTag ("AmmoText");
SpecialWeapon = GameObject.FindGameObjectWithTag ("Special");
SpecialWeapon.GetComponent<Text> ();
}
public void LateUpdate(){
MissileCountText.GetComponent<Text>() = MissileCount.ToString();
//------------------------------------------------------------------------------------------
if (Target == null) {
Activate = false;
}
//------------------------------------------------------------------------------------------
Comment
To edit Text you need use the "text" property after get the component.
$$anonymous$$issileCountText.GetComponent<Text>().text = $$anonymous$$issileCount.ToString();
Your answer
![](https://koobas.hobune.stream/wayback/20220612100613im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adventure Game Help 0 Answers
Random Text like Minecraft 1 Answer
Text is not visible when changing text color 0 Answers
Can't change to new string line inside my script 0 Answers
Removing an item from Inventory and updating item count on HUD 0 Answers