Hi again!
Sorry for dumb question, but how can I order a list of GameObjects by their x-position? I tried this:
camPoint = new List<GameObject>(GameObject.FindGameObjectsWithTag("CameraPoint"));
camPoint = camPoint.OrderBy(camPoint => camPoint.transform.position.x);
Unfortunately, those two lines return an error:
`camPoint’ conflicts with a declaration in a child block.
Is there any way how to order this list? I have no idea, where is the problem, I’ve tried many things, but the error is still returned.
Thanks for any tips! Have a nice day…
-Vojta
your just getting an error because you’re reusing a variable name that’s already used.
camPoint is already defined as the enumerable of gameobjects, then you try to use it as the parameter name for each camPoint in the linq statement to orderby.
You’re going to have more issues though because OrderBy returns an IEnumerable, not a List.
Try doing:
camPoints = new List<GameObject>(GameObject.FindGameObjectsWithTag("CameraPoint").OrderBy((c) => c.transform.position.x));
OK, thank you very much for reply, I’m gonna try to experiment with this.
By the way, I use this to control size of camera following a player. Don’t you know any intuitive system for camera control? It’s kind of odd that some sort of that system is missing.
First, camera control is a very specialized thing. The way you expect your camera to work isn’t how I expect mine to work. Unity isn’t going to include very specialized tools for that that only a few people will use. Instead they have it set up in a way that allows you to do whatever you want with it (it has a transform, and you can move it). The asset store probably has some specialized camera motion tools that may or may not be what you need.
As for what you’re trying to accomplish.
Well… I’m assuming you have a bunch of points that define points on a path that you want your camera to pass through. I wouldn’t be treating it based on Tag name, and using FindGameObjectsWithTag to gather all them up. What if I wanted to create 2 paths?
Personally I’d probably have some way of defining paths… maybe a ‘curves’ package. There’s several out there. Some set up would be say you’re defining ‘cat-mull rom curves’, and each gameobject is a knot in that curve. You might go and have a parent gameobject, this represents the curve, and then all the child gameobjects of that gameobject are the knots, and they numbered (the name maybe?). Then you could use the algorithm for cat-mull roms to move through those points.