Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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.

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

Check if mouse is down while in Edit Mode 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Raycast with strange Behaviour 0 Answers

C# Mouse Look (Input.GetAxis("MouseX&Y")) 0 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