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
0
Question by mink_123 · Dec 17, 2014 at 09:56 PM · c#instantiateprefabcolors

i want to assign different colors to rows or different colors to the brick?

I am Instantiating prefabs to build a wall of bricks using this code.

 void Start () {
         float z = 2.2f;
         float y = 1f;
         float x = -12f;
         float increment = 2f;
          float spacing = 1.3f;
             for (y = 1f; y < 3.8f; y++) {
                 for (x = -14; x < 3.5f; x++) {
                     Instantiate(brick, new Vector3(x, y, z)*spacing, Quaternion.identity);
 
             }
         }
     }

I would be very helpful if someone can guide me to proceed to assign different colors to rows or each brick.

Comment
Add comment · Show 1
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 justin35f · Dec 17, 2014 at 10:04 PM 0
Share

There are a huge variety of ways to do this. One option is creating a few different prefabs that have slightly different properties (such as color) and depending on your x, and y values within the nested for loops, instantiate a different brick.

Another way to do it is to get access to the renderer of the game object, then manually set the color on the material, like this:

 renderer.material.color = Color.red;

Another option is to not create a brick wall with so many different bricks, but to rather model a brick wall in a modelling program (I recommend Blender) and use that. If you need the wall to be destructable, then you can create a model of the wall, then create a few other 'destructed' models to use, and upon destruction, instantiate a random destructed version.

There are lot's of options, and it depends on things such as your skill level, your requirements, etc...

I know this isn't an answer (hence the comment) but hopefully it steers you in the right direction.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do i Instantiate a prefab with specific assests included 3 Answers

,Instantiating Prefab in C# 0 Answers

Issue Instantiating prefab in C# 0 Answers

Issue Instantiating prefab in C# 2 Answers

Destroying Objects. 1 Answer


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