Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JGBrands · Jul 02, 2018 at 09:31 AM · uiinputcamera-movement

Blocking Input.ButtonDown and Input.GetAxis when over UI,Block Input.GetButton when over an UI Element

Hi there,

I tried searching for a concise answer to my problem, but so far I've had no luck. I get that the answer lies somewhere in UnityEngine.EventSystemsbut so far I've not been successful in using this correctly.

The problem is as follows: I got a Camera with a script attached to it:

 public class PlayerCameraController : MonoBehaviour
 {
     public float LookSpeed = 0.4f;
     public float ZoomSpeed = 1.0f;
     public float TiltZoomMin = 70.0f;
     public float TiltZoomMax = 45.0f;
     public float ZoomMin = 20.0f;
     public float ZoomMax = 10.0f;
 
     private float ZoomPercentage = 0.0f;
 
     private void Update()
     {
         if (Input.GetButton("MoveCamera"))
         {
             var mouseX = Input.GetAxis("MouseX");
             var mouseY = Input.GetAxis("MouseY");
 
             transform.position = new Vector3(
                 transform.position.x + mouseX * LookSpeed,
                 transform.position.y,
                 transform.position.z + mouseY * LookSpeed);
         }
 
         var scrollValue = Input.GetAxis("MouseScroll");
 
         if (scrollValue != 0.0f)
         {
             ZoomPercentage = Mathf.Clamp(ZoomPercentage + scrollValue * ZoomSpeed, 0.0f, 1.0f);
 
             transform.position = new Vector3(
                 transform.position.x,
                 Mathf.Lerp(ZoomMin, ZoomMax, ZoomPercentage),
                 transform.position.z);
 
             transform.rotation = Quaternion.Euler(
                 Mathf.Lerp(TiltZoomMin, TiltZoomMax, ZoomPercentage),
                 0.0f,
                 0.0f);
         }
     }
 }

This script works great, the problem is that there's no way for me to block the camera from being zoomed while my cursor is over the UI. I cannot exactly see how to do this with UnityEngine.EventSystems either, as there's no reference to the scroll wheel? And it seems to ignore IPointerClickDown too.

Any help here would be greatly appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by donutLaserDev · Jul 02, 2018 at 02:37 PM

https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html

This will tell you whether the cursor is above the UI element.

Comment
Add comment · Show 1 · Share
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
avatar image JGBrands · Jul 02, 2018 at 03:34 PM 0
Share

Is that really the recommended way of doing it? Cause that feels kinda dirty to me. If this is indeed the proper way of handling this, I will accept your answer.

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

159 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I get text in a canvas to display the name of a key that is chosen by the player in the input panel of the launcher? 1 Answer

EventSystem events reaching parent EventTrigger? 0 Answers

Showing UI image when inside a trigger and then pressing a button 2 Answers

Why does the keyboard control what button is selected? 2 Answers

is it Possible to use navigation on non UI elements? 1 Answer


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