예제 #1
0
    private bool Obstacle(GameObject other)
    {
        SwapScript swap            = other.GetComponent <SwapScript>();
        Vector3    target          = swap.spawnPoint.position;
        int        ignoreSwapLayer = ~(1 << swapLayer);

        Debug.DrawLine(this.gameObject.transform.position, target);
        return(Physics.Linecast(this.gameObject.transform.position, target, ignoreSwapLayer));
    }
예제 #2
0
    private void Swap()
    {
        SwapScript playerInRange = objectInRange.GetComponent <SwapScript>();

        playerInRange.active = true;

        if (this.gameObject.layer != slimeLayer)
        {
            this.active   = false;
            objectInRange = null;
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        float startX = -numBlocks / 2f;

        blocks       = new GameObject[numBlocks];
        playerBlocks = new GameObject[numBlocks];

        swapQueue              = new Queue <int[]>();
        swapScript             = gameObject.GetComponent <SwapScript>();
        swapScript.sortManager = this;

        // Make int arr and shuffle
        int[] arr = new int[numBlocks];
        for (int i = 0; i < arr.Length; i++)
        {
            arr[i] = i;
        }
        // shuffle
        for (int i = arr.Length - 1; i >= 0; i--)
        {
            int randomIndex = Mathf.FloorToInt(Random.value * i);
            int placeholder = arr[i];
            arr[i]           = arr[randomIndex];
            arr[randomIndex] = placeholder;
        }

        for (int i = 0; i < numBlocks; i++)
        {
            float colorVal = 1f * arr[i] / numBlocks;
            blocks[i]       = createBlock(new Vector3(startX + i, 3, 0), arr[i], new Color(0, colorVal, colorVal), false);
            playerBlocks[i] = createBlock(new Vector3(startX + i, 0, 0), arr[i], new Color(colorVal, colorVal, colorVal), true);
            playerBlocks[i].GetComponent <BlockScript>().val   = arr[i];
            playerBlocks[i].GetComponent <BlockScript>().index = i;
        }

        arr = bubbleSort(arr);
        int[] swap = swapQueue.Dequeue();
        startBlockSwap(swap[0], swap[1]);
    }
예제 #4
0
    // if the icon is clicked on
    void OnMouseOver()
    {
        // if the icon is left clicked
        if (Input.GetMouseButtonDown(0))
        {
            objectPropertiesScript = linkedObject.GetComponent <ObjectProperties>();

            // if icon is look
            if (iconType == 0)
            {
                // output text description stored on object

                // if object has a description field with a string in it
                if (!String.Equals(objectPropertiesScript.description, ""))
                {
                    // set the starting time for the text
                    clickedTime = Time.time;

                    objectText = objectPropertiesScript.description;
                }
            }

            // if icon is use
            else if (iconType == 1)
            {
                // carry out the proper action based ont he object's properties

                // if the use type is 1, AKA swap
                // swap the visibility from on to off or vice versa
                if (objectPropertiesScript.useType == 1)
                {
                    SwapScript swapScript = linkedObject.GetComponent <SwapScript>();

                    swapScript.firstClicked = true;

                    //if (swapScript.status == true)
                    //{
                    //    swapScript.status = false;
                    //}
                    //else
                    //{
                    //    swapScript.status = true;
                    //}

                    iconHandlerScript.beingUsed = false;
                }
            }

            //if icon is store
            else if (iconType == 2)
            {
                if (objectPropertiesScript.storable == true)
                {
                    inventoryArray = iconHandlerScript.invArray;

                    for (int i = 0; i < inventoryArray.Length; i++)
                    {
                        if (inventoryArray[i].transform.childCount == 0)
                        {
                            linkedObject.transform.position = new Vector3(inventoryArray[i].transform.position.x,
                                                                          inventoryArray[i].transform.position.y, inventoryArray[i].transform.position.z - 0.5f);
                            linkedObject.transform.rotation = inventoryArray[i].transform.rotation;

                            linkedObject.transform.parent = inventoryArray[i].transform;
                            objectPropertiesScript.stored = true;
                            iconHandlerScript.beingUsed   = false;
                            return;
                        }
                    }
                }

                iconHandlerScript.beingUsed = false;
            }
        }
    }
예제 #5
0
 private void Start()
 {
     script = GameObject.Find("EventSystem").GetComponent <SwapScript>();
 }