コード例 #1
0
    public void UpdateHeightTEST() //this is the old one, with obly 1 cube selector
    {
        currentHeight = Mathf.Clamp(currentHeight, 0, StageBuilder.MAX_HEIGHT);

        float      newHei           = transform.position.y;
        Vector3    fromTopPosition  = new Vector3(transform.position.x, StageBuilder.MAX_HEIGHT, transform.position.z);
        Vector3    toBottomPosition = new Vector3(transform.position.x, 0, transform.position.z);
        Vector3    direction        = toBottomPosition - fromTopPosition;
        RaycastHit hit;

        if (Physics.Raycast(fromTopPosition, direction, out hit))
        {
            if (hit.transform.gameObject.GetComponent <StageObject>() != null)
            {
                //height will be the highest block in that tile plus that block's height, same if it's an object
                StageObject obt = hit.transform.gameObject.GetComponent <StageObject>();
                newHei = obt.GridPosition.Height + obt.GetCurrentItemHeight();
            }
            else if (hit.transform.gameObject.GetComponent <StageBlock>() != null)
            {
                StageBlock block = hit.transform.gameObject.GetComponent <StageBlock>();
                newHei = block.GridPosition.Height + block.GetCurrengBlockHeight();
            }
            else
            {
                newHei = 0;
            }
        }

        currentHeight      = newHei;
        transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
    }
コード例 #2
0
    /// <summary>
    /// updates the height in that tile using a raycast from maximum height to the selector's height
    /// </summary>
    /// <param name="newHeight"></param>
    public void UpdateHeight()
    {
        currentHeight = Mathf.Clamp(currentHeight, 0, StageBuilder.MAX_HEIGHT);
        float          highestHei  = 0;
        List <Vector3> activeCubes = GetActiveCubes();

        for (int i = 0; i < activeCubes.Count; i++)
        {
            float      newHei           = transform.position.y;
            Vector3    fromTopPosition  = new Vector3(activeCubes[i].x, StageBuilder.MAX_HEIGHT, activeCubes[i].z);
            Vector3    toBottomPosition = new Vector3(activeCubes[i].x, 0, activeCubes[i].z);
            Vector3    direction        = toBottomPosition - fromTopPosition;
            RaycastHit hit;

            if (Physics.Raycast(fromTopPosition, direction, out hit))
            {
                if (hit.transform.gameObject.GetComponent <StageObject>() != null)
                {
                    //height will be the highest block in that tile plus that block's height, same if it's an object
                    StageObject obt = hit.transform.gameObject.GetComponent <StageObject>();
                    newHei = obt.GridPosition.Height + obt.GetCurrentItemHeight();
                }
                else if (hit.transform.gameObject.GetComponent <StageBlock>() != null)
                {
                    StageBlock block = hit.transform.GetComponent <StageBlock>();
                    newHei = block.GridPosition.Height + block.GetCurrengBlockHeight();
                }
                else
                {
                    newHei = 0;
                }

                highestHei = newHei > highestHei ? newHei : highestHei;
            }

            currentHeight = highestHei;                                                           //newHei;
        }
        transform.position = new Vector3(transform.position.x, highestHei, transform.position.z); //currentHeight
    }