Example #1
0
    public bool Spawn(Game.EnemyType type)
    {
        Vector3 position = Vector3.zero;

        for (int tries = 0; tries < TryCountPerSpawn; tries++)
        {
            position.x = Random.Range(Bounds.bounds.min.x, Bounds.bounds.max.x);
            position.y = Random.Range(Bounds.bounds.min.y, Bounds.bounds.max.y);
            position.z = Random.Range(Bounds.bounds.min.z, Bounds.bounds.max.z);
            RaycastHit hit;
            if (Physics.Raycast(position, Vector3.down, out hit, FloorCastLength, CheckGroundMask))
            {
                position = hit.point + Vector3.up * OccluderCheckHeight;
                if (!Physics.CheckSphere(position, OccluderCheckRadius, CheckSpawnPositionMask))
                {
                    Game.TrySpawnEnemy(type, position, Quaternion.identity);
                    return(true);
                }
                else
                {
                    //Debug.Log(string.Format("NoSpace {0}", position));
                }
            }
            else
            {
                //Debug.Log(string.Format("NoFloor {0}", position));
            }
        }
        return(false);
    }