コード例 #1
0
    ISpawnable SpawnObject(float min, float max, ISpawnable prefab)
    {
        Vector3 pos = Vector3.zero;
        int     tries;

        for (tries = 0; tries < spawnRetries; ++tries)
        {
            pos  = Random.onUnitSphere.SetY(0f).normalized *(Random.Range(min, max) + prefab.GetSpawnRadius());
            pos += target.transform.position;
            if (CheckPositionValidity(pos, prefab.GetSpawnRadius()))
            {
                break;
            }
        }
        if (tries == spawnRetries)
        {
            return(null);
        }
        ISpawnable spawn = Instantiate(prefab, pos, yRotationOnly ? Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) : Random.rotation);

        spawn.SetParent(this);
        return(spawn);
    }