Esempio n. 1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))                        // If clicking
     {
         ray = camera.ScreenPointToRay(Input.mousePosition); // Create a ray from the mouse position
         if (Physics.Raycast(ray, out hit))                  // If something was hit
         {
             foreach (MonoBehaviour script in hit.collider.GetComponents <MonoBehaviour>())
             {
                 if (script is IClickable)
                 {
                     IClickable clickable = (IClickable)script;
                     clickable.LeftClick();
                 }
             }
         }
     }
     else if (Input.GetMouseButtonDown(1))
     {
         ray = camera.ScreenPointToRay(Input.mousePosition); // Create a ray from the mouse position
         if (Physics.Raycast(ray, out hit))                  // If something was hit
         {
             foreach (MonoBehaviour script in hit.collider.GetComponents <MonoBehaviour>())
             {
                 if (script is IClickable)
                 {
                     IClickable clickable = (IClickable)script;
                     clickable.RightClick();
                 }
             }
         }
     }
 }
    public override void OnHandleInput()
    {
        if (!handler.mousePointer.overClickable)
        {
            handler.SwitchContext(GetComponent <ContextDefault>());
            return;
        }

        // Handle the case where the input context hasn't changed but the mouse is
        // pointing at a different clickable than in the previous Update().
        if (clickable != handler.mousePointer.clickable)
        {
            SetClickable(handler.mousePointer.clickable);
        }

        if (Input.GetMouseButtonDown(0)) // Left mouse button
        {
            clickable.LeftClick(handler.playerInControl);
        }
        if (Input.GetMouseButtonDown(1)) // Right mouse button
        {
            clickable.RightClick(handler.playerInControl);
        }
    }