CodePudding user response:
CodePudding user response:
//create a GameObject
Var textObj=new GameObject (" textObj ");
//on a transform, as a child node, the transform is the canvas of the transform of the panel, because you said that the script is hung on a panel of
TextObj. Transform. SetParent (transform);
//add Text component
Var text=textObj. AddComponent(a);
//TODO: setting the attribute
CodePudding user response:
Well, learn to see prompt content, meet the problem is the basis to solve the problem: error promptIf you carefully read the hint of text, will know that a GameObject only one Graphic components,
Then you have to add Text GameObject above have a Image components, then the Image is from Graphic and Text derived classes,,
Know the cause of the problem, as long as you dynamically add Text, make sure no other from Graphic derived components, such as a new common GameObject, then AddComponent
Finally: see the error message, it's very important!
CodePudding user response: