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 RSud · Nov 27, 2010 at 07:40 AM · meshprefabmultiple

multiple meshes in a prefab and how to texture?

I expect I can place multiple meshes in a single prefab. And that the multiple meshes in the prefab will retain their position relative to each other as I rotate and display the prefab. Is this true?

In particular, I have a mesh of a space ship. I want to put an billboard (Unity plane) over each engine exhaust (there are 2 engine exhausts) and then place a texture with transparency on each billboard to simulate engine glow. I will update the engine glow texture every .05 seconds to get the flickering effect.

I do a 'renderer.material.mainTexture = shiptexture;' each frame to apply a texture to the ship mesh in the prefab.

My question is, if I have two billboards in the same prefab what is my code to apply a separate texture to each of the billboards (unity planes)?

Thanks for any help!

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 duck · Nov 27, 2010 at 08:23 AM

Each visible gameobject within your prefab will have its own renderer component, so you will have to find references to those components in your scripts in exactly the same way as you would any other component (even if it wasn't in a prefab).

For example, if your script that controls ship is also in charge of applying textures to these billboards, you might have something like this included in the script placed on your ship (assuming every ship has 2 exhausts, and they are named "Exhaust 1" and "Exhaust 2"):

var exhaust1 : Renderer; var exhaust2 : Renderer;

function Start() {

 // we search the child objects connected to this ship to find the 2 exhausts:
 exhaust1 = transform.Find("Exhaust 1").renderer;
 exhaust2 = transform.Find("Exhaust 2").renderer;

}

function Update() {

 // the code which you use to make the exhaust flicker will include this:...
 exhaust1.material.maintexture = ....etc;
 exhaust1.material.maintexture = ....etc;

}

Alternatively (and I prefer this method) you might consider making a separate "Exhaust" script, and place it on the exhaust objects directly. This simplifies things in that you can simply reference the renderer directly, so your entire "Exhaust" script might look like this, including the billboarding code and the code to modulate the engine glow texture:

var glowTextures : Texture2D[];

function Start() {

 EngineFlicker();

 // billboard loop - runs every frame:
 while (true) {
     transform.rotation = Camera.main.transform.rotation;
     yield;
 }

}

function EngineFlicker() {

 // engine flicker loop - runs every half second:
 while (true) {
     renderer.material.mainTexture = glowTextures[Random.Range(0,glowTextures.Length)];
     yield WaitForSeconds(0.5);
 }

}

Comment
Add comment · Show 6 · 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 RSud · Nov 27, 2010 at 11:10 PM 0
Share

Looks good!

In your first example, with 'Exhaust 1' and 'Exhaust 2' how would these names be assigned to the billboard meshes?

avatar image duck ♦♦ · Nov 28, 2010 at 09:58 AM 0
Share

Those would be the actual names of the gameobjects within your prefab. You have to name them before making the prefab - or modify them by placing the prefab back in the scene, modifying the version in the scene, then applying those changes back to the prefab.

avatar image RSud · Nov 28, 2010 at 06:09 PM 0
Share

ahh... ohh... Looks like I missing something big. I thought I could add multiple meshes to the same prefab but just tried it and I can not.

So if I want to add two billboards (Unity planes) to my prefab that holds the space ship mesh looks like I must create two seperate prefabs, one for each billboard/plane, yes?

I am starting to look for documentation or samples on how I connect the space ship prefab to the two billboard (plane) prefabs. I see some references to a hierarchy. How do I do this? If anyone can point me that would be great.

avatar image duck ♦♦ · Nov 28, 2010 at 07:29 PM 0
Share

no, a prefab can contain multiple objects (each gameobject can have its own mesh). Your prefab can contain as many objects you like, parented in whatever hierarchical configuration that you like. You just can't change this arrangement without putting the prefab into the scene, making changes, then applying those changes back to the prefab.

avatar image RSud · Nov 30, 2010 at 01:28 AM 0
Share

Thank you for the info on how to apply textures to multiple meshes in one prefab.

I will need more instruction on how to put multiple meshes into one prefab and give each mesh a unique name. Would you be able to point me to documentation or tuturials that cover specifically how to do this? Thanks so much....!

Show more comments

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

No one has followed this question yet.

Related Questions

Prefab Materials and Meshes being deleted, How can I stop this 1 Answer

duplicate a prefab then change the model? 1 Answer

how to have multiple meshes be part of a single instantiated prefab gameobject? 1 Answer

I can modify the GameObject transform using the inspector, how can I modify the mesh as well? 0 Answers

How to import a mesh NOT as a Prefab 2 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