mercredi 18 juin 2014

Assign values to objects in a list using LINQ


Vote count:

0




I have some objects that have positions. I'd like to shuffle the objects' positions. (ie, take all the positions, shuffle, and reassign for each object).


This is what I have, but I'd like something more elegant (in 1 line).



var i = 0;
var tags = transform.FindChild("Step 1").Cast<Transform>().Where(t => t.name.StartsWith("Tag")).ToList();
var newPosition = tags.Select(t => t.position).OrderBy(t => Random.Range(0, 3)).ToArray();
tags.ForEach(t => t.position = newPosition[i++]);


asked 1 min ago

Fabricio

1,320





Aucun commentaire:

Enregistrer un commentaire