Esempio n. 1
0
    private void Awake()
    {
        // May need to wait for LevelManager to finish loading level before spawning player

        int       spawnIndex = GameManager.GM.GetLevelManager().curSpawnIndex;
        LevelExit curExit    = exits[spawnIndex];

        Vector3   spawnPosition = curExit.GetSpawnPoint();
        Direction playerDir     = curExit.GetSpawnDirection();

        BlockDirection blockDir = BlockDirection.Null;

        GameObject[] camBlockingVolumes = curExit.cameraBlockingVolumes;
        Vector3      camOffset          = Vector3.zero;

        // Apply offset for each camera blocking volume player is spawning into
        foreach (GameObject camBlockingVolume in camBlockingVolumes)
        {
            // Calculate camera offset
            Bounds camBlockBounds = camBlockingVolume.GetComponent <Collider>().bounds;

            blockDir = camBlockingVolume.GetComponent <CameraBlockCollision>().blockDir;

            if (blockDir == BlockDirection.PosX)
            {
                Vector3 edge = camBlockBounds.center + camBlockBounds.extents;
                camOffset.x = edge.x - spawnPosition.x + playerSize;
            }
            else if (blockDir == BlockDirection.NegX)
            {
                Vector3 edge = camBlockBounds.center - camBlockBounds.extents;
                camOffset.x = edge.x - spawnPosition.x - playerSize;
            }
            else if (blockDir == BlockDirection.PosZ)
            {
                Vector3 edge = camBlockBounds.center + camBlockBounds.extents;
                camOffset.z = edge.z - spawnPosition.z + playerSize;
            }
            else if (blockDir == BlockDirection.NegZ)
            {
                Vector3 edge = camBlockBounds.center - camBlockBounds.extents;
                camOffset.z = edge.z - spawnPosition.z - playerSize;
            }
        }

        GameManager.GM.SpawnPlayer(spawnPosition, playerDir, camOffset);
    }