Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 headkit · Apr 22, 2010 at 02:11 PM · texturematerialrandomoutofbounds

randomly changing texture of material

hi folks!

i want to set up a simple card game, searching for the best method of texturing the different card fronts. i was wondering if it would be the best to put all the different card front pictures (which should be placed randomly later) in one big texture an then show only one part of the texture in the material (like masking). is this the best way and if so - how could i do that!? :-)

thnx!

edited: just for the record: if i want to change the Offset of a texture in a material, how could i do that?

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 headkit · Apr 22, 2010 at 02:59 PM 0
Share

or isn't it also possible to get something to work with

GetComponentInChildren

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by spinaljack · Apr 22, 2010 at 02:28 PM

Grouping textures is generally good practice to reduce memory requirements but mostly for things like particle or flare effects. A way to randomise textures for cards would be to set up an array containing all your card textures, you can do this by declaring an array called var cardMats: material[]; then you can assign any number of them manually in the inspector.

Then when you want to apply a material you'd generate a random number to pick one from the array, something like this:

mat = Random.Range(0, cardMats.length)

static function Range (min : int, max : int) : int Description Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

If max equals min, min will be returned. The returned value will never be max unless min equals max. So you wont have to worry about array out of bounds this this method.

You assign the material to the renderer with this:

renderer.material = cardMats[mat];

Comment
Add comment · Show 2 · 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 headkit · Apr 22, 2010 at 02:48 PM 0
Share

thank you, i will try to try that... just for the record: if i want to change the Offset of a texture in a material, how could i do that?

avatar image spinaljack · Apr 22, 2010 at 02:56 PM 1
Share

That's another question for another post ;)

avatar image
0

Answer by 3ddf · Apr 22, 2010 at 02:28 PM

Hi headkit,

This post on the unity forums explains the texture atlasing stuff fairly well, it should point you in the right direction I think.

http://forum.unity3d.com/viewtopic.php?t=7207&postdays=0&postorder=asc&start=0

Comment
Add comment · Show 2 · 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 headkit · Apr 22, 2010 at 02:46 PM 0
Share

phuuu, thats hard stuff for one beginner like me. but thank you!

avatar image BerggreenDK · Dec 04, 2010 at 02:57 AM 0
Share

hehe, you want fancy effects, then you gotta do fancy work. :o) Hope you will be curious enough to learn this part too.

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

Multiple random tiled textures in one material 1 Answer

Multiple textures in one material 0 Answers

Trying to change button background using materials 1 Answer

How can i change detail texture? 1 Answer

Setting texture for a transparent material in c# 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