private Mesh Generate()
    {
        Debug.Assert(starCount < 65536, "Number of stars must less than 65536");

        var random = new System.Random(seed);

        var mesh = new Mesh();
        var vertices = new Vector3[starCount];
        var indices = new int[starCount];
        var colors = new Color[starCount];

        for (var i = 0; i < starCount; ++i)
        {
            vertices[i] = random.OnUnitSphere();

            indices[i] = i;

            colors[i] = starColors[random.Next(starColors.Length)];
            colors[i].a = (0.2f + 0.8f * MathUtils.NextFloat(random)) * (1 - (Mathf.Abs(vertices[i].y)));
        }

        mesh.vertices = vertices;
        mesh.colors = colors;
        mesh.SetIndices(indices, MeshTopology.Points, 0);

        return mesh;
    }
Example #2
0
    //private Collider collider;

    private void Start()
    {
        var collider = GetComponent<Collider>();

        deposits = new List<Targetable>();

        var random = new System.Random();
        
        var count = random.Next(1, 10);

        for (int i = 0; i < count; ++i)
        {
            var offset = random.OnUnitSphere() * collider.bounds.extents.sqrMagnitude;
            var outerPoint = offset + transform.position;
            Vector3 surfacePos = transform.position;

            //fire a ray inwards to find our own surface
            foreach (var hit in Physics.RaycastAll(outerPoint, -offset, collider.bounds.extents.sqrMagnitude))
            {
                if (hit.collider != collider)
                {
                    continue;
                }

                surfacePos = hit.point;
                break;
            }
            
            var deposit = new GameObject("Deposit");
            var depositTargetable = deposit.AddComponent<Targetable>();
            depositTargetable.Faction = "resource";

            deposit.transform.position = surfacePos;
            deposit.transform.SetParent(transform, true);

            deposits.Add(depositTargetable);
        }
    }