Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by johnkol · Aug 09, 2010 at 03:44 PM · texturematerialrendertextureguitextdynamic

Need help with creating dynamic textures.

Hello everyone,

I am currently working on a game based on atoms. The game allows you to play around with all kinds of atoms from the Periodic Table. In order to reduce the art assets I want to create textures dynamically and slap it onto the atoms (spheres). I can do this easily in editor using a RenderTexture. However, when I try doing it in script (C#) the text simply doesn't show up in the RenderTexture. Here is my code:

void GenerateTexturesForAtoms() { for (int i = 0; i < atom_list.Count; ++i) { GameObject cam_text = Instantiate(Resources.Load("CamText")) as GameObject;

     RenderTexture render_texture = new RenderTexture(256, 256, 0);
     render_texture.isPowerOfTwo = true;
     render_texture.Create();

     cam_text.GetComponent&lt;GUIText&gt;().text = "Hydrogen";
     cam_text.GetComponent&lt;Camera&gt;().transform.Rotate(new Vector3(0, 0, 0));
     cam_text.GetComponent&lt;Camera&gt;().transform.position = new Vector3(0, 15, 0);
     cam_text.GetComponent&lt;Camera&gt;().targetTexture = render_texture;

     Material atom_mat = new Material(Shader.Find("Diffuse"));
     atom_mat.SetTexture("_MainTex", render_texture);
     (atom_list[i] as GameObject).renderer.material = atom_mat;
 }

}

I just need to figure out how to get the GUIText to render onto my target texture. I think there is something really silly that I am doing. Any help would be great!

Thank you very much!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by johnkol · Aug 09, 2010 at 07:13 PM

Okay I think I figured it out, or rather found an alternative.

I used a 3DText (TextMesh) instead. I created a prefab with a Camera, Plane and 3DText. The Plane will hold the material you want to show up on the atom. The 3DText will go on top of this plane. The Camera is then set perpendicular to them and thus captures the 3dText over the plane onto a RenderTexture. At this point I have pretty much what I wanted. I doubt if this is the most efficient way to do it, but works pretty well for my game. Also, make sure you use the 3DText Shader instead of the default one. Its available here. Else your text will appear scrambled when you try to use custom font.

Here is the code I used in case any wants to try it out:

void GenerateTexturesForAtoms() { for (int i = 0; i < atom_list.Count; ++i) { GameObject cam_text = Instantiate(Resources.Load("CamText")) as GameObject;

     RenderTexture render_texture = new RenderTexture(256, 256, 0);
     render_texture.isPowerOfTwo = true;
     render_texture.Create();

     cam_text.GetComponentInChildren&lt;TextMesh&gt;().text = atom_list[i].GetComponent&lt;Atom&gt;().element_name;
     cam_text.GetComponent&lt;Camera&gt;().transform.Rotate(new Vector3(-90, 0, 0));
     cam_text.GetComponent&lt;Camera&gt;().transform.position = new Vector3(90, 10 * i, 0);
     cam_text.GetComponent&lt;Camera&gt;().targetTexture = render_texture;

     Material atom_mat = new Material(Shader.Find("Diffuse"));
     atom_mat.SetTexture("_MainTex", render_texture);
     atom_mat.SetTextureOffset("_MainTex", new Vector2(0.2f, -0.025f));
     (atom_list[i] as GameObject).renderer.material = atom_mat;
 }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mterlecki1 · Apr 04, 2013 at 11:07 PM 0
Share

John, I have a similar problem. How did you create the Camera, Plane and 3DText? Did you attach the Plane and 3DText to the Camera? You code doesn't ever reference the plane or 3DText objects so I assume you did the parenting etc. in the editor or inspector. Can you tell me how you did it?

Thanks

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

dynamic images for textures ar runtime 2 Answers

Converting a RenderTexture to a Texture2D for use in a shader 2 Answers

How to update texture during runtime to display damage? 0 Answers

Dynamic Material & Textures 1 Answer

[SOLVED] Dynamic texture setting 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges