コード例 #1
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    IEnumerator LocationOfStars()
    {
        //--------------

        for (int v = 0; v < vertices.Length; v++)
        {
            yield return(null);

            posX = ((vertices[v].x * localsclTel) + (thisTransform.position.x + 9999)) / detailScaleUniverse;
            posZ = ((vertices[v].z * localsclTel) + (thisTransform.position.z + 9999)) / detailScaleUniverse;

            vertices[v].y = Mathf.PerlinNoise(posX, posZ) * heightScaleUniverse;

            cosQtObj = Mathf.Cos(vertices[v].y + thisTransform.position.x + thisTransform.position.z + v + 9.5f) * 10.5f;
            float lperlinf = Mathf.PerlinNoise(cosQtObj, cosQtObj);

            if (v % 5 == 0 && lperlinf > 0.5f && lperlinf < 0.52f)
            {
                starPosition = new Vector3(vertices[v].x * localsclTel + thisTransform.position.x, vertices[v].y, vertices[v].z * localsclTel + thisTransform.position.z);
                starFromPool = StarPool.GiveStar();

                if (starFromPool != null)
                {
                    if (stars.Count == 0)
                    {
                        starFromPool.transform.position = starPosition;
                        starFromPool.SetActive(true);
                        stars.Add(starFromPool);
                    }
                    else
                    {
                        positionTaken = false;
                        for (int i = 0; i < stars.Count; i++)
                        {
                            if (stars[i].transform.position == starPosition)
                            {
                                positionTaken = true;
                            }
                        }
                        if (positionTaken == false)
                        {
                            starFromPool.transform.position = starPosition;
                            starFromPool.SetActive(true);
                            stars.Add(starFromPool);
                        }
                    }
                }
            }
        }

        //--------------
    }
コード例 #2
0
    public static StarPool instance; //holds singleton reference

    void Start()
    {
        //set up the singleton
        if (instance == null)              //if instance isn't set
        {
            instance = this;               //set it to this instance
            DontDestroyOnLoad(gameObject); //Don't destory this gameObject
        }
        else                               //otherwise, if we have a singleton already
        {
            Destroy(gameObject);           //Destroy this instance
        }
    }
コード例 #3
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    void OnDestroy()
    {
        //--------------

        for (int i = 0; i < stars.Count; i++)
        {
            if (stars[i] != null)
            {
                StarPool.TakeStar(stars[i]);
            }
        }
        stars.Clear();

        //--------------
    }