Esempio n. 1
0
    public void doWork()
    {
        if (hitInfo.collider == null && triggeredItem == null)
        {
            targetPosition   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            targetPosition.y = transform.position.y;
        }
        else if (hitInfo.collider != null && triggeredItem == null)
        {
            if (hitInfo.collider.tag == "Untagged" || hitInfo.collider.tag == "Floor")
            {
                targetPosition   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                targetPosition.y = transform.position.y;
            }
            else
            {
                Debug.Log("Hellor");

                ObjectInterface obj = hitInfo.collider.gameObject.GetComponent <ObjectInterface>();
                obj.Work();
            }
        }
        else if (hitInfo.collider == null && triggeredItem != null)
        {
            triggeredItem = null;
        }
        else if (hitInfo.collider != null && triggeredItem != null)
        {
            if (hitInfo.collider.tag == "Untagged" || hitInfo.collider.tag == "Floor")
            {
                triggeredItem = null;
            }
            else
            {
                ObjectInterface obj = hitInfo.collider.gameObject.GetComponent <ObjectInterface>();
                obj.ApplyItem(triggeredItem);
                triggeredItem = null;
            }
        }
        else
        {
            Debug.Log("Error");
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            if (activeInv)
            {
                inventory.SetActive(false);
                activeInv = false;
            }
            else
            {
                inventory.SetActive(true);
                activeInv = true;
            }
        }
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            //Set up the new Pointer Event
            m_PointerEventData = new PointerEventData(m_EventSystem);
            //Set the Pointer Event Position to that of the mouse position
            m_PointerEventData.position = Input.mousePosition;

            //Create a list of Raycast Results
            List <RaycastResult> results = new List <RaycastResult>();
            //RaycastResult results;
            //Raycast using the Graphics Raycaster and mouse click position
            m_Raycaster.Raycast(m_PointerEventData, results);

            //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
            foreach (RaycastResult result in results)
            {
                Debug.Log(result.gameObject.tag);
                GameObject      temp = result.gameObject;
                ObjectInterface obj  = temp.GetComponent <ObjectInterface>();
                obj.Work();
                break;
            }
        }
    }