Esempio n. 1
0
    private void AssignFlag(Transform previousPlaceholder, Transform currentPlaceholder)
    {
        PlaceholderFlag flag = currentPlaceholder.gameObject.AddComponent <PlaceholderFlag>();

        if (previousPlaceholder.forward == currentPlaceholder.right)
        {
            flag.OccupiedSide = -currentPlaceholder.right;
        }
        else
        {
            flag.OccupiedSide = currentPlaceholder.right;
        }
    }
Esempio n. 2
0
    //Assumption: wall.lossyScale.x == 1
    private List <Vector3> CreateEnemyPositions(GameObject innerPlaceholder, GameObject outerPlaceholder)
    {
        List <Vector3>  enemyPositions   = new List <Vector3>();
        Vector3         innerPosition    = innerPlaceholder.transform.position;
        PlaceholderFlag flag             = outerPlaceholder.GetComponent <PlaceholderFlag>();
        Vector3         innerScale       = innerPlaceholder.transform.lossyScale;
        Vector3         outerScale       = outerPlaceholder.transform.lossyScale;
        Vector3         enemyScale       = enemyPrefab.transform.lossyScale;
        float           wallXScale       = 1; //wall.lossyScale.x
        float           emptySpaceOffset = 1;
        float           xSpace           = (outerScale.x / 2) - (innerScale.x / 2) - wallXScale;
        float           zSpace           = innerScale.z - (2 * emptySpaceOffset);

        List <float> zOffsets = GetDefaultEnemyZOffsets(zSpace, enemyScale);

        foreach (float zOffset in zOffsets)
        {
            Vector3 enemyOffset = new Vector3(
                (innerScale.x / 2) + (xSpace / 2),
                (innerScale.y / 2) + enemyScale.y,                       //enemyScale.y / 2
                zOffset
                );
            if (flag != null)
            {
                if (outerPlaceholder.transform.right == flag.OccupiedSide)
                {
                    enemyOffset.x *= -1; //because enemyOffset is set to right side by default
                }
                Vector3 enemyPosition = innerPosition + (innerPlaceholder.transform.rotation * enemyOffset);
                enemyPositions.Add(enemyPosition);
            }
            else
            {
                Vector3 enemyPosition = innerPosition + (innerPlaceholder.transform.rotation * enemyOffset);
                enemyPositions.Add(enemyPosition);
                enemyOffset.x *= -1;
                enemyPosition  = innerPosition + (innerPlaceholder.transform.rotation * enemyOffset);
                enemyPositions.Add(enemyPosition);
            }
        }
        return(enemyPositions);
    }
    private void InstantiateSideWalls(Transform currentPlaceholder, out GameObject leftWall, out GameObject rightWall)
    {
        PlaceholderFlag flag = GetFlag(currentPlaceholder);

        if (flag != null)
        {
            float side = MathMethod.VectorSign(flag.OccupiedSide);
            if (side == 1)
            {
                leftWall  = InstantiateSideWall(currentPlaceholder, -side);
                rightWall = null;
            }
            else
            {
                leftWall  = null;
                rightWall = InstantiateSideWall(currentPlaceholder, -side);
            }
        }
        else
        {
            leftWall  = InstantiateSideWall(currentPlaceholder, -1);
            rightWall = InstantiateSideWall(currentPlaceholder, 1);
        }
    }
    private PlaceholderFlag GetFlag(Transform placeholder)
    {
        PlaceholderFlag flag = placeholder.gameObject.GetComponent <PlaceholderFlag>();

        return(flag);
    }