- Home /
Question by
migardene · Apr 20, 2020 at 08:51 AM ·
animationspritesheet
I try swap sprite with Late Update method and got foreach error for SpriteRenderer type
Hi I try to swap out all sprite that shown in this video at around 20:00 https://www.youtube.com/watch?v=rMCLWt1DuqI
foreach (var renderer in GetComponentInChildren<SpriteRenderer>())
{
}
When I use this I got error "foreach statement cannot operate on variables of type 'SpriteRenderer' because 'SpriteRenderer' does not contain a public instance definition for 'GetEnumerator'"
Or is there any better way to do this since it's 2020 now?
Comment
I try assign it to array first before putting it in foreach loop and it kind of working somehow
SpriteRenderer[] sprites = GetComponentsInChildren<SpriteRenderer>();
foreach (var renderer in sprites)
will still apreciate the answer for better solution to swap out sprites