- Home /
Problem scripting with SetSiblingIndex()
Hi, I'm doing a system where the game calculates 83 different rolls, and returns the DMG that everyone does on a variable. I am trying to order the different rolls by the DMG they do, but I'm having some trouble doing it. Here's the code:
Answer by Bunny83 · Dec 11, 2021 at 04:56 PM
Your duplicate post got deleted. Please edit your question when you want to add more details and don't open new questions on the same issue.
Anyways... This line:
previousDMG = roll.GetComponent<Transform>().GetSiblingIndex();
should probably be this:
previousIndex = roll.GetComponent<Transform>().GetSiblingIndex();
Though I would highly recommend to not use the ordering of the transform components for sorting. Apart from that you essentially doing a single iteration of bubble sort that would not sort all objects and is extremely inefficient.
It would be way better to store your objects in a List<DMGCalculator>
and just use the Sort method. This uses quick sort and would be much better for performance reasons. Once your List is sorted you can simply rearrange the transform components according to the list, if that's even necessary.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Multiple array variable 2 Answers
How do I make a game like Super Time Force? 1 Answer
Raw Image wont show in game view 1 Answer