- Home /
How to see what element is the current one
I have a number of cards in the List 'hand'. Each turn another card gets added which works perfectly. Now I'm trying to, when you play a card, that card accesses the List to shift all other cards' transforms to fill the gap. But only the numbers in the List that are above that card's number.
So my question is actually, is there a built-in variable that gives the number/rank of the current element?
Answer by Nanity · Aug 06, 2012 at 10:59 AM
I assume you're using a list?
JS:
var handcards : List.; var card : Card;
function Update (){ Debug.Log(getIndex(card)); }
function getIndex(element : Card) : int { for (var i : int = 0; i < handcards.Count; i++) { if (handcards[i] == card) return i; } // in case the card is not in your hand return -1 return -1; }
Answer by Seth-Bergman · Aug 06, 2012 at 10:21 AM
I believe what you want is List.IndexOf