• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Cpl_Punishment88 · Mar 01, 2021 at 02:35 PM · inputmousemousedrag

Input System Right Click and Move

Hi! I am making a 2D digital board game and adding in some player controls for camera control using the new Unity Input System (version 2020.2.6f1). For mouse and keyboard setup, I am able to measure a click and a hold (using an Interaction), but I can't seem to combine the hold of left, right, or middle button click in combination with the mouse movement. I tried to make a "Add Button with One Modifier Composite" or "Two Modifier Composite" to an Axis, but that just combines two or three buttons together. I need something that combines the Vector2 delta of a mouse with a mouse or keyboard button click (and hold).

Right now, I have a separate action for the mouse movements to set a state and then one for pointer moves to do something based on state.

Is my approach the right approach or is a Vector2 with a button modifier exist in Unity (or something like it)?

Here is my early input code:

 using UnityEngine;
 using UnityEngine.InputSystem;
 
 public class HumanPlayerInput : MonoBehaviour
 {
     [SerializeField]
     Player HumanPlayer;
     [SerializeField]
     Camera PlayerCamera;
     PointerChangeState CameraState;
 
     void OnEnable()
     {
         CameraState = PointerChangeState.None;
         if(PlayerCamera = null)
             SetPlayerCamera();
     }
 
     public void OnSetPan(InputAction.CallbackContext context) => SetPointerState(context.ReadValueAsButton(), PointerChangeState.Pan);
 
     public void OnSetDrag(InputAction.CallbackContext context) => SetPointerState(context.ReadValueAsButton(), PointerChangeState.Drag);
 
     public void OnSetRotate(InputAction.CallbackContext context) => SetPointerState(context.ReadValueAsButton(), PointerChangeState.Rotate);
 
     public void OnPan(InputAction.CallbackContext context) => PanCamera(context.ReadValue<Vector2>());
 
     public void OnPointerMovement(InputAction.CallbackContext context)
     {
         switch(CameraState)
         {
             case PointerChangeState.Drag:
                 break;
             case PointerChangeState.Pan:
                 PanCamera(context.ReadValue<Vector2>());
                 break;
             case PointerChangeState.Rotate:
                 break;
             default:
                 break;
         }
     }
 
     public void OnZoom(InputAction.CallbackContext context) => PlayerCamera.orthographicSize = context.ReadValue<float>() * 100f;
 
     void PanCamera(Vector2 changeInPan) => PlayerCamera.transform.Translate(changeInPan * 500f);
 
     void SetPointerState(bool isButtonPressed, PointerChangeState stateToEnable) => CameraState = isButtonPressed ? stateToEnable : PointerChangeState.None;
 
     void SetPlayerCamera()
     {
         var playerCameraTransform = transform.Find("PlayerCamera");
         if(playerCameraTransform == null)
             PlayerCamera = Camera.main;
         else
         {
             PlayerCamera = playerCameraTransform.GetComponent<Camera>();
             if(PlayerCamera == null)
                 PlayerCamera = Camera.main;
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

151 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I separate OnMouseDown() from OnMouseDrag() 0 Answers

Mouse Input Lag 3 Answers

Input System Can't Catch Event on Update 0 Answers

How can I detect the mouse is moving through code? 3 Answers

Is there a built-in function to determine if any GUI item has been clicked? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges