Syntax Problem in C#

Hi, I’m following a tutorial for scripting AI in a car game and it’s written in JavaScript and I’m trying to convert it to C#.

Right off the bat i’m stuck because I need to use lists and I can’t figured out how to make this C# applicable:

List<Transform> pathObjs = new List<Transform>();
		pathObjs = transform.GetComponentsInChildren<Transform>();

I know that i’m trying to take an Array and add it directly to a list but I don’t know the correct way to do this.

Can someone tell me the correct way to go about this?

Thanks :wink:

You can add “using System.Linq” to the top and then do:

List<Transform> pathObjs = transform.GetComponentsInChildren<Transform>().ToList();

or you can do this:

List<Transform> pathObjs = new List<Transform>();
pathObjs.Add(transform.GetComponentsInChildren<Transform>());

Thank you so much, that worked. I was sitting here for like 2 hours on google trying to get an answer. Should have just posted here at the beginning.

See if I have any more questions relating to this, can I just post a reply to you instead of creating a new thread for every problem?

Well, you can try but I’m not always sitting around on the forums. I’m supposed to be working on my own Unity game. :wink: You’d probably get a faster response from other people making a new post.

Alright, i’ll just do that.