Accessing second material

 
Post new topic   Reply to topic    Unity Community Index // Scripting
View previous topic :: View next topic  
Author Message
fallingbrickwork



Joined: 16 Mar 2009
Posts: 221
Location: Co Donegal, Ireland

PostPosted: Sat Nov 07, 2009 7:52 pm    Post subject: Accessing second material Reply with quote
Hi all,

I am using SetTexture to change a material's texture at runtime and everything is working great. My problem is that some of my models have multiple materials and it is not always the first material's texture i need to change.

How can I access a model's second material or third etc and use SetTexture to change them?

Btw, I'm coding in C#

Many thanks in advance,
Matt.

_________________
Horror - FPS && ProjectX2
FearedFutureGames website: fearedfuturegames.com
Check out my youtube: fallingbrickwork's YouTube Channel
Dev Route: Modo 401, Unity Pro, VS2008
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Jessy



Joined: 07 Jun 2007
Posts: 2757
Location: NE Ohio, USA

PostPosted: Sat Nov 07, 2009 9:00 pm    Post subject: Reply with quote
A model with multiple materials will have an array in the Inspector. Just use the appropriate index in renderer.materials with your SetTexture.

http://unity3d.com/support/documentation/ScriptReference/Renderer-materials.html



Screen shot 2009-11-07 at 2.59.57 PM.png

Back to top
View user's profile Send private message Visit poster's website
fallingbrickwork



Joined: 16 Mar 2009
Posts: 221
Location: Co Donegal, Ireland

PostPosted: Sat Nov 07, 2009 9:50 pm    Post subject: Reply with quote
Thanks Jessy and sorry for even asking the question... i looked in the scripting reference and didn't even see renderer.materials! My fault, i was using renderer.material

Thanks again for pointing me to it.

Regards,
Matt.

_________________
Horror - FPS && ProjectX2
FearedFutureGames website: fearedfuturegames.com
Check out my youtube: fallingbrickwork's YouTube Channel
Dev Route: Modo 401, Unity Pro, VS2008
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Post new topic   Reply to topic    Unity Community Index // Scripting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum