The CelestialBody class in C# represents a celestial object such as a planet, moon, or star. The GetComponentsInChildren method is used to retrieve all the child objects of a CelestialBody instance that have a specified component type.
Code Example 1:
// retrieve all the Light components attached to the child objects of a CelestialBody instance Light[] lights = celestialBody.GetComponentsInChildren();
// iterate over each light component and set its intensity to 0.5 foreach (Light light in lights) { light.intensity = 0.5f; }
Description of Example 1:
This example retrieves all the Light components attached to the child objects of a CelestialBody instance and then iterates over each one to set its intensity to 0.5.
Code Example 2:
// retrieve all the Rigidbody components attached to the child objects of a CelestialBody instance Rigidbody[] rigidBodies = celestialBody.GetComponentsInChildren();
// apply a force to each rigidbody component foreach (Rigidbody rigidbody in rigidBodies) { rigidbody.AddForce(Vector3.up * 10.0f); }
Description of Example 2:
This example retrieves all the Rigidbody components attached to the child objects of a CelestialBody instance and then applies a force to each one to make it move upwards.
Package/Library:
The CelestialBody class and the GetComponentsInChildren method are part of the Unity game engine's standard library.
C# (CSharp) CelestialBody.GetComponentsInChildren - 27 examples found. These are the top rated real world C# (CSharp) examples of CelestialBody.GetComponentsInChildren extracted from open source projects. You can rate examples to help us improve the quality of examples.