예제 #1
0
    // Update is called once per frame
    void Update()
    {
        // create a ray cast that orignates from the cursor position
        Vector3 forward = transform.TransformDirection (Vector3.forward) * 5;
        RaycastHit hit;
        if (Physics.Raycast (transform.position, forward, out hit)) {
            if (currentObject == null) { //IF we haved no current object
                currentObject = hit.transform.gameObject; //save the object
                HighlightCurrentObject (); //and highlight it
            } else if (hit.transform != currentObject.transform) { //ELSE IF we have hit a different object
                RestoreCurrentObject (); //THEN restore the old object
                currentObject = hit.transform.gameObject; //save the new object
                HighlightCurrentObject (); //and highlight it

            }
        } else //ELSE no object was hit
            RestoreCurrentObject (); //THEN restore the old object

        //select one slot
        if (Physics.Raycast (transform.position, forward, out hitToSlotOrItem)) {
            itemIsHit = hitToSlotOrItem.transform.gameObject.GetComponent(typeof(Item)) as Item;
            slotIsHit = hitToSlotOrItem.transform.gameObject.GetComponent(typeof(SlotController)) as SlotController;

            //inventoryIsHit = hitToSlotOrItem.transform.gameObject.GetComponent(typeof(InventoryController)) as InventoryController;

            if(slotIsHit != null){
                slotIsHit.RayCastToSlot();
            }
            else{
                //slotIsHit.RayCastNotToSlot();
            }
            if(itemIsHit != null){
                itemIsHit.RayCastToItem();
            }
            else{
                //itemIsHit.RayCastNotToItem();
            }
            /*if(inventoryIsHit != null){
                inventoryIsHit.RayCastToInventory();
            }*/
        }

        if (Input.GetKeyDown (KeyCode.Return) || grab) {
            grab = false;
            if (currentObject != null){
                currentObject.SendMessage("Select");
            }
        }
    }