Example #1
0
    /// <summary>
    /// Returns a new random generated planet located at given absolute position
    /// </summary>
    /// <param name="position">Position in wich planet wil be generated</param>
    /// <returns>Random generated planet</returns>
    public GameObject BuildPlanet(Vector3 position)
    {
        GameObject go = null;

        Quaternion rotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f));

        go = GameObject.Instantiate(prefab, position, rotation);

        if (go != null)
        {
            Planet            pl   = go.GetComponent <Planet>();
            Planet.Properties prop = new Planet.Properties(
                Random.Range(massThreshold.x, massThreshold.y),
                Random.Range(densityThreshold.x, densityThreshold.y)
                );

            pl.SetProperties(
                prop,
                colors[Random.Range(0, numColors)],
                backgrounds[Random.Range(0, numBackgrounds)],
                textures[Random.Range(0, numTextures)]
                );
            SetResources(go, prop.planetRadius);
        }

        return(go);
    }
 private void Awake()
 {
     Planet.Properties prop = new Planet.Properties(Mass, Density);
     this.SetProperties(prop, color, backgroundColor, texture);
 }