How do i get List of all Planes GameObjects ?
This line give me first time only one result if in the Hierarchy i have a Plane object that it's name is Plane.
List<GameObject> planes = (from g in UnityEngine.Object.FindObjectsOfType<GameObject>() where g.name.Equals(planeName) select g).ToList();
But i have in the Hierarchy also Planes named: Plane (3) and Plane (4) and Plane (1) so it's not in the List. How can i List any object that contain the name Plane so also objects with the name Plane or Plane (23) will be listed ?
Second question i have is how do i know if object is really type of Plane ? When i'm looking at Plane Inspector i can see the name Plane or Plane12 but who said it's Plane and not a Cube that renamed to Plane12 ? I mean if i want to List only objects that are type of Plane not by name but by type ? And how can i check alone in the editor not in a script and identify that the object is really plane and not cube or Sphere ?
Answer by UnityCoach · Dec 03, 2016 at 08:46 PM
You can use string.Contains instead, like
List<GameObject> planes = (from g in UnityEngine.Object.FindObjectsOfType<GameObject>() where g.name.Contains(planeName) select g).ToList();
Though, you're right, a Plane is nothing but an object with a mesh filter that points to the plane mesh. So you could check if it has a MeshFilter component, and if the Mesh is the builtin Plane mesh.