- Home /
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!?
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.
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
Follow this Question
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