0
\$\begingroup\$
var selection = Selection.objects.OfType<GameObject>().ToList();
tempTransforms = selection;

selection is List and tempTransform is Transform[] And I want to assign the selection to the tempTransform.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is there a reason you aren't using tempTransforms = Selection.transforms? \$\endgroup\$
    – Jimmy
    Aug 28 '18 at 0:27
  • \$\begingroup\$ @Jimmy: I forgot that was an option! I think that would be a better answer than what I wrote below, if you'd care to post it as an answer. :) \$\endgroup\$
    – DMGregory
    Aug 28 '18 at 12:09
2
\$\begingroup\$

For simple C# syntax questions that don't require game development expertise, don't forget to search our general programming sister site StackOverflow first - they'll often have more coverage of topics like these.

// Store intermediate selection as an array so we can use the ConvertAll method.
var selection = Selection.objects.OfType<GameObject>().ToArray();

// Provide a lambda to look up the corresponding Transform, given a GameObject.
tempTransform = Array.ConvertAll(selection, item => item.transform);
\$\endgroup\$
4
\$\begingroup\$

The simplest way to get an array of Transforms from the selection is

tempTransform = Selection.transforms;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .