示例#1
0
    bool SwapPlatformPositions(int num1, int num2)
    {
        if (num1 == 0 || num2 == 0)
        {
            Debug.Log("errors with default platform?");
            // first element is off limits to swap
            return(false);
        }
        // switch the current locations of platforms as well as their originally set locations
        Vector3 temp = locations[num1];

        platformParents[num1].transform.position = locations[num2];
        platformParents[num2].transform.position = temp;
        locations[num1] = locations[num2];
        locations[num2] = temp;
        int tempNum = currentList[num1];

        currentList[num1] = currentList[num2];
        currentList[num2] = tempNum;
        // swap the stored position of these platforms
        TextParentFollow scriptTemp = numbersFollow[num1];
        GameObject       followTemp = scriptTemp.parent;

        numbersFollow[num1].parent = numbersFollow[num2].parent;
        numbersFollow[num1]        = numbersFollow[num2];
        numbersFollow[num2].parent = followTemp;
        numbersFollow[num2]        = scriptTemp;
        // change where the numbers associated with platform are
        return(true);
    }
示例#2
0
    void ShowPlatform(string name, Vector3 pos, Color col, int num)
    {
        locations[num] = pos;
        // set the original position of object
        GameObject layer      = Instantiate(topLayer, new Vector3(pos.x, pos.y, pos.z - 3), Quaternion.identity);
        GameObject background = Instantiate(platformBackground, new Vector3(pos.x, pos.y, pos.z - 2), Quaternion.identity);

        background.GetComponent <Renderer>().material.color = col;
        BackgroundFollow backgroundScript = background.GetComponent <BackgroundFollow>();

        backgroundScript.parent = layer;
        GameObject       text   = Instantiate(platformName, pos, Quaternion.identity);
        TextParentFollow script = text.GetComponent <TextParentFollow>();

        script.parent  = layer;
        script.xOffset = 0;
        text.transform.SetParent(tCanvas.transform);
        Text ourText = text.GetComponent <Text>();

        ourText.text = name;
        GameObject numText = Instantiate(platformName, pos, Quaternion.identity);

        numText.transform.SetParent(tCanvas.transform);
        script        = numText.GetComponent <TextParentFollow>();
        script.parent = layer;
        float platformWidth = background.transform.localScale.x * 0.5f;

        script.xOffset     = (platformWidth) - .15f;
        numbersFollow[num] = script;
        ourText            = numText.GetComponent <Text>();
        ourText.text       = (num + 1).ToString();
        ourText.fontSize   = 19;
        if (num == 0)
        {
            // don't allow default platform to be moved!
            Destroy(layer.GetComponent <DragHandler>());
            Destroy(background.GetComponent <BackgroundFollow>());
        }
        LayerChildren layerScript = layer.GetComponent <LayerChildren>();

        layerScript.background = background;
        layerScript.text       = text;
        layerScript.numText    = numText;
        platformParents[num]   = layer;
    }