- Home /
How do I rearrange sprites' transform coordinates by name?
What Im basically have is a stack of sprites from top to bottom (see image1) and Im trying to implement an onClick function where it would rearrange the coordinates of said sprites in alphabetical order. I know its probably something simple. The sprites are in a List, and I have half of it figured out but if i click the button, it only sorts it in the inspector and i dont know how i would type in the code to rearrange the images. See the attaced images if youre confused.
The images are children of an empty game object which has a content size fitter and vertical layout
public List<Transform> carList = new List<Transform>();
//
public void SortName (bool sort)
{
if (sort)
{
carList = carList.OrderBy(tile => tile.name).ToList(); //sorts the list in the inspector panel
//code here if names are sorted
}
}
so then i want to be grey car, yellow car, then green car from top down.
Answer by YasinJavaid_ · Sep 07, 2017 at 01:26 PM
Hi @Kineticon can u please send ur showing code.
solution: recall your showing method.
what do you mean my showing code? and how would i recall my showing code? the only thing im having trouble with is basically moving images' coordinations by sorting them alphabetically. Ive figured out how to do it in the List but not to actually change the position.
u sort ur list but not update in scene or panel but always when you update screen you have to update values in screen. i was just asking you which method u r using for showing ur cars. or u have just make panel and try to sort them alphabetically if u r doing this u must have to make method to show ur updated cars. thanks
the sprites have the button component attached to it...
public GameObject Type35$$anonymous$$;
public GameObject Slipstream;
public GameObject AP2000S;
public void Start()
{
AP2000S.SetActive(true);
Slipstream.SetActive(false);
Type35$$anonymous$$.SetActive(false);
CarSelected = 1;
}
public void loadAP2ks()
{
AP2000S.SetActive(true);
Slipstream.SetActive(false);
Type35$$anonymous$$.SetActive(false);
CarSelected = 1;
}
public void load35Type$$anonymous$$()
{
AP2000S.SetActive(false);
Slipstream.SetActive(false);
Type35$$anonymous$$.SetActive(true);
CarSelected = 2;
}
public void loadSlipS()
{
AP2000S.SetActive(false);
Slipstream.SetActive(true);
Type35$$anonymous$$.SetActive(false);
CarSelected = 3;
}
This code is attached to the sprites for the onClick function that shows the actual car.
Your answer
Follow this Question
Related Questions
Strange behavour when drawing on texture 0 Answers
Image distorts when created in C# 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Duplicate UI object 2 Answers