There is a script for tugging items in the inventory. It works using the interfaces IBeginDragHandler, IDragHandler and IEndDragHandler. How to make Unity distinguish which mouse button I clicked. I can drag objects by holding the right or left mouse button, but I want to hold the right mouse button and I can simply drag objects. And when you click the left mouse button, my items were divided by 2.

    2 answers 2

    You can add input validation (just not like the previous speaker - why do you need to know each Update what you clicked, if you can check it when pressed?) And the IPointerClickHandler interface for "sharing" :) In your case, this:

     public void OnBeginDrag(PointerEventData eventData) { if (Input.GetMouseButtonDown(1)) { //Ρ‚ΡƒΡ‚ Π»ΠΎΠ³ΠΈΠΊΠ° Π½Π°Ρ‡Π°Π»Π° пСрСтаскивания. ΠΈ ΠΊΠ°ΠΊΠΎΠΉ-Π½ΠΈΠ±ΡƒΠ΄ΡŒ Ρ„Π»Π°ΠΆΠΎΠΊ _isDraging = true, //ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ провСряСтся Π² ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄Π°Ρ… пСрСтягивания. } } public void OnPointerClick(PointerEventData eventData); { if (Input.GetMouseButtonDown(0)) { //Ρ‚ΡƒΡ‚ Π»ΠΎΠ³ΠΈΠΊΠ° раздСлСния. } } 

    The OnPointerClick method will only work if the cursor has been lowered and raised above the same element.

      Then, for starters, before all actions, determine the button pressed by the player:

      https://docs.unity3d.com/ru/530/ScriptReference/Input.GetMouseButtonDown.html

       // ΠŸΡ€ΠΈΠΌΠ΅Ρ€ using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) Debug.Log("Pressed left click."); // Π»ΠΈΠ±ΠΎ ваш ΠΊΠΎΠ΄ if (Input.GetMouseButtonDown(1)) Debug.Log("Pressed right click."); // Π»ΠΈΠ±ΠΎ ваш ΠΊΠΎΠ΄ if (Input.GetMouseButtonDown(2)) Debug.Log("Pressed middle click."); // Π»ΠΈΠ±ΠΎ ваш ΠΊΠΎΠ΄ } }