- Home /
Move object in array of objects
Hello, I'm pretty new to Unity and C#, and creating my little card based game i encountered a problem: There are 5 cards on each side, card 1 from one side attack card 1 from other side etc. When one card dies (for example 1 on side 1) than i want to move all the cards -1 on position (so 2 goes to 1, 3 to 2, 4 to 3, 5 to 4, and last one is null). I want to do it without sending single stats like HP, DMG and others to card on lower position but i don't know how. I tried something like that, but it didn't do anything: public MyCardsClass[] MyObject;
public void MyFunction()
{
for (int y = 0; y <= 9; y++)
{
if (MyObject[y].Dead = true)
{
if (y < 4) { MyObject[y] = MyObject[y + 1]; } //4 is last card on one side, we don't want to assign 5 to 4 (5 is 1st card on 2nd side)
else if (y < 9) { MyObject[y] = MyObject[y + 1]; } //9 is last card on 2nd side
}
}
}
Hope now you understand what i want to do... so... is there any way to "shift" those object like I try to do or I need to move it by GameObject somehow?
Comment