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 NewfieJoe · Jan 15, 2011 at 02:08 AM · javascripttextureinstantiatearray

Applying different textures to spawned objects.

I'm instantiating a grid of cloned objects and need to apply a different texture to each depending on the values in a multidimensional array from a script attached to the main camera. I'm a bit rusty and can't remember how to give each instantiated object the appropriate texture. Can someone please help me out?

for (var y = 0; y < gridY; y++) { for (var x=0;x < gridX; x++) { var pos = Vector3 (x + gridOffset, 0, y + gridOffset) * spacing; currTile = GS_Games[gameNum, y, x];

 // GS_Pics[currTile] holds the material to be applied
 Instantiate(GS_Tile, pos, Quaternion.identity);
 }

}

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 NewfieJoe · Jan 16, 2011 at 08:44 PM 0
Share

In the end I created the objects off camera in the editor and cloned each one as needed. It's a cludgy way of doing it though.

2 Replies

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

Answer by DaveA · Jan 15, 2011 at 02:27 AM

Something on the order of

currTile.renderer.material.mainTexture = TGS_Pics[currTile]; // if TGS_Pics are textures

currTile.renderer.material.mainTexture = TGS_Pics[currTile].mainTexture; // if TGS_Pics are materials and you just want to transfer the texture

Comment
Add comment · Show 3 · 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 NewfieJoe · Jan 15, 2011 at 02:59 AM 0
Share

Each tile is being rendered with a pictures based on an array. currTile is an integer with the reference, hence GS_pics[currTile] pointing to the material I need to use. I tried instantiated with an array of Gameobjects but something seems to be wrong with the following line when I try that. GS_Tiles[currTile] = Instantiate(GS_Tile, pos, Quaternion.identity);

avatar image NewfieJoe · Feb 19, 2011 at 02:19 PM 0
Share

Turned out I simply forgot to add " as GameObject" at the end of the command. :P

avatar image DaveA · Feb 19, 2011 at 07:46 PM 0
Share

Added some clarification to my answer

avatar image
1

Answer by Jessy · Jan 15, 2011 at 02:29 AM

http://unity3d.com/support/documentation/ScriptReference/Material-mainTexture.html

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 NewfieJoe · Jan 15, 2011 at 02:48 AM 0
Share

This is for multiple objects in a grid that are spawned from script. $$anonymous$$inimum of 81 for a small puzzle to a max of 324 for a large one, some using text, some with numbers, some with slices of a picture etc.. I can't figure how to reference them to change the materials after they are instantiated. Brain stalled. :P

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

Compare texture from array to another one in list 1 Answer

Instantiate object in for loop with array 2 Answers

Array variable assigned to instantiated object changes in all instantiated objects? 1 Answer

How can i show the texture in the array? 2 Answers

Instantiating from an object that's in an array 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