コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        var starCount = Random.Range(MinStars, MaxStars);

        for (int i = 0; i < starCount; i++)
        {
            var obj         = GameObject.Instantiate(m_StarObject, this.transform);
            var randomScale = Random.Range(MinScale, MaxScale);
            obj.transform.localScale = new Vector3(randomScale, randomScale, 1f);
            var randomPosition = WorldDimensionUtils.GetRandomWorldPosInCamera(Camera.main) * 3f;
            obj.transform.position = new Vector3(randomPosition.x, 0f, randomPosition.z);
            SetRandomColor(obj);
        }
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        var randomIndex = Random.Range(0, BackgroundSprites.Length - 1);
        var sprite      = BackgroundSprites[randomIndex];

        if (sprite != null)
        {
            var obj      = new GameObject("Background Image");
            var renderer = obj.AddComponent <SpriteRenderer>();
            renderer.sprite       = sprite;
            renderer.sortingOrder = 1;
            obj.transform.Rotate(Vector3.right, 90f);
            var randomPosition = WorldDimensionUtils.GetRandomWorldPosInCamera(Camera.main);
            obj.transform.position = new Vector3(randomPosition.x, 0f, randomPosition.z);
            obj.transform.parent   = this.transform;
        }
    }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        var showPlanetRatio = Random.Range(0f, 1f);

        if (showPlanetRatio <= ShowPlanetOdds)
        {
            var randomIndex = Random.Range(0, PlanetSprites.Length - 1);
            var sprite      = PlanetSprites[randomIndex];
            if (sprite != null)
            {
                var obj      = new GameObject("Planet");
                var renderer = obj.AddComponent <SpriteRenderer>();
                renderer.sprite       = sprite;
                renderer.sortingOrder = 2;
                obj.transform.Rotate(Vector3.right, 90f);
                var randomScale = Random.Range(MinScale, MaxScale);
                obj.transform.localScale = new Vector3(randomScale, randomScale, 1f);
                var randomPosition = WorldDimensionUtils.GetRandomWorldPosInCamera(Camera.main);
                obj.transform.position = new Vector3(randomPosition.x, 0f, randomPosition.z);
                obj.transform.parent   = this.transform;
            }
        }
    }