Home > other >  Unity to dynamically create text, urgent
Unity to dynamically create text, urgent

Time:09-16

How to hang on the canvas panel scripts to dynamically create text text

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 prompt
If 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 To it, it is absolutely no problem!

Finally: see the error message, it's very important!

CodePudding user response:

reference faint a leisurely yo reply: 3/f
well, learn to see the prompt content, meet the problem is the basis to solve the problem: error prompt
If 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 To it, it is absolutely no problem!

Finally: see the error message, it's very important!


Oh oh oh, sorry, oversight, second floor as a person