Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (selectedItem != null)
        {
            Cursor.SetCursor(selectedItem.icon, Vector2.zero, CursorMode.Auto);
        }
        else
        {
            Cursor.SetCursor(basePointer, Vector2.zero, CursorMode.Auto);
        }

        //if we click the mouse
        if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject())
        {
            //make a raycast from the camera to the world
            Ray        clickRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit clickHit; //this holds information about what we clicked on
            //fire the raycast and retrieve the data
            if (Physics.Raycast(clickRay, out clickHit))
            {
                //if we hit an interactable
                if (clickHit.transform.GetComponent <Interactable>())
                {
                    //interact
                    //Debug.Log("Interactable");
                    //pass our current action to the interactable and retrieve a response
                    //lastResponse = clickHit.transform.GetComponent<Interactable>().Interact(currentAction);
                    currentTarget = clickHit.transform.GetComponent <Interactable>(); //we're going to store the interactable as our target
                }
                else if (clickHit.transform.GetComponent <PathSystem>())              //If we've clicked on something with a path system (the backdrop)
                {
                    //vector3 point
                    clickedPoint = clickHit.point;                                 //we'll want this soon
                    PathSystem p = clickHit.transform.GetComponent <PathSystem>(); //Store a reference to the path system for convenience
                    //pass to avatar
                    Vector3 point = p.PathPoint(clickedPoint.x);                   //get the end point of the path from the path system by providing the click
                    avatar.SetPath(p.path, point);                                 //pass the path to our avatar as well as the end point
                }
            }
            UpdateUI();
        }
    }