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 Panik.Studios · Jul 11, 2014 at 05:06 AM · arraymaterialrandom

Changing Objects Material Using My Array

Making A Poker Game of Sorts I have my Own Array of Materials "CardsList"

1)How would I change a Cards Material using my Array of Materials? 2)How do I make sure a material from my Array isn't being used more then once? 3)How to I make sure All Materials can be used again when I start a new hand?

Hopefully You'll see what I mean when you look at me psuedo Script Line //Unity Answers Please Help Me//

 var CardList = new Material[52];  //All the different cards faces//
 var FaceMat : Material; //The Back Of the Card//
 
 //The Cards//
 var HC1 : GameObject;
 var HC2 : GameObject;
 var FaceCard1 : GameObject;
 var FaceCard2 : GameObject;
 var FaceCard3 : GameObject;
 var FaceCard4 : GameObject;
 var FaceCard5 : GameObject;
 
 //Dealer Functions//
 var StartGame = false;
 var Deal = false;
 var Flop = false;
 var Turn = false;
 var River = false;
 
 //Faces Cards Down on the Table//
 function Start () {
 FaceCard1.renderer.material = FaceMat;
 FaceCard2.renderer.material = FaceMat;
 FaceCard3.renderer.material = FaceMat;
 FaceCard4.renderer.material = FaceMat;
 FaceCard5.renderer.material = FaceMat;
 HC1.renderer.material = FaceMat;
 HC2.renderer.material = FaceMat;
 
 }
 
 function Update () {
 
     if(StartGame == true){
         Dealing();
         
     }
 }
 
 //UNITY ANSWERS HELP ME//
 function Dealing(){
 StartGame = false;
 yield WaitForSeconds(2);
 Deal = true;
 FaceCard1.renderer.material = <Random material from cardslist>
 FaceCard2.renderer.material = <Random Material from cardslist, but cant already be in use by another object>
 }
 
 


PS WTF Unity you still haven't fixed the Tag Glitch on your website? How hard can it be after making a game engine.. come on!?

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 Panik.Studios · Jul 11, 2014 at 06:03 AM 0
Share

bumpty dumpty sat on a wall

1 Reply

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

Answer by SirCrazyNugget · Jul 11, 2014 at 05:23 AM

1) I wouldn't use separate materials for each card, just move the UV coordinates to ensure you have batching.

2) Create a duplicate array of the materials (or UV positions if you choose to do (1) instead) then remove them from the list when they're used.

3) Repopulate the duplicate array from the original array.

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 Panik.Studios · Jul 11, 2014 at 06:07 AM 0
Share

Ahh that's a good suggestion.. Im looking for an easy out, and Ive never really worked with arrays yet.. so I want to mess with them on this project (it's such a simple game that doing the materials thing wont be too big on performance).. I'll do what you mentioned if I run aground with the array thing.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

renderer.material doesnt work 3 Answers

Cant change GO material with multipli material 1 Answer

Randomize Array, pick object and change material? 1 Answer

Trying to switch Textures on object based on timer 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