InterplanetaryObject.GetNearestPlanet C# (CSharp) Method

GetNearestPlanet() public static method

public static GetNearestPlanet ( Vector3 pos ) : Gravity,
pos Vector3
return Gravity,
    public static Gravity GetNearestPlanet(Vector3 pos)
    {
        Gravity nearestPlanet = null;
        float nearestDistance = int.MaxValue;

        Gravity[] planetList;
        if (Application.isPlaying) {
            planetList = Gravity.PlanetList.ToArray();
        }
        else {
            planetList = GameObject.FindObjectsOfType<Gravity>();
        }

        foreach (Gravity planet in planetList) {
            float dist = Vector3.Distance(planet.transform.position, pos);
            if (dist < nearestDistance) {
                nearestPlanet = planet;
                nearestDistance = dist;
            }
        }

        return nearestPlanet;
    }

Usage Example

Exemplo n.º 1
0
 public void CheckOrientation()
 {
     _io = GetComponent <InterplanetaryObject>();
     _io.NearestPlanet = InterplanetaryObject.GetNearestPlanet(transform.position);
     Initialize();
     UpdateOrientation();
     Deinitialize();
 }
All Usage Examples Of InterplanetaryObject::GetNearestPlanet
InterplanetaryObject