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 theblitz · Sep 01, 2016 at 06:02 AM · inputmanagergettouch

Why is my Touches array empty?

I am using CnInputControls. When I click a button it seems to pass multiple events to the Update method.

I tried using the following code

if(CnInputManager.GetButtonDown("Fire3")&&CnInputManager.GetTouch(0).phase==TouchPhase.Began){

But I then get IndexOutOfBounds in the GetTouch because the touches array is empty.

If I leave out the GetTouch part then the if statement is always true.

What am I missing?

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
1
Best Answer

Answer by NerdClown · Sep 01, 2016 at 07:29 AM

I don't have experience with CnInputManager, but I used regular Unity touch input for an app a few years back. It looks the same, but please bear with me if it works entirely different!

What seems a little odd to me is how you combine "get button down" and GetTouch(0). I would guess it should be something like this (with regular Unity input stuff)

  if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 

Usually this type of structure is made to make sure we don't start looking for Touch 0 before we're actually sure there is one. The && operator is lazy, meaning that if the left side is false, it won't evaluate the right side, saving us the null pointer exception that it would cause.

Of course, the whole ButtonDown && GetTouch(0) might just be some CnInput stuff that I'm not familiar with.

Comment
Add comment · Show 4 · 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 theblitz · Sep 01, 2016 at 08:00 AM 0
Share

The GetButtonDown also exists in Input and is meant to give me the button that was clicked. GetButton works just as well.

Nevertheless, touchCount is always 0. I never get any touches from it.

avatar image NerdClown theblitz · Sep 01, 2016 at 08:13 AM 1
Share

Yes, that is true, but I guess what is bothering me is the combination of GetTouch and GetButton/GetButtonDown.

The reason I'm confused is probably that in my perception, the GetTouch is for touch devices like phones or tablets while the GetButtonDown I only ever used for things that has actual buttons ... like mouse/keyboard and such.

What type of device is your project gonna run on?

avatar image theblitz NerdClown · Sep 01, 2016 at 10:22 AM 0
Share

$$anonymous$$aybe that is my problem. I am new to all this.

It is going to run on Android but I am testing it inside Unity because I can't get UnityRemote to work. $$anonymous$$aybe that is my problem.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

InputManager crashes unity when downloaded from the Asset Server. 1 Answer

How to add custom input to InputManager? 2 Answers

guitexture to act as a button on the keyboard or mouse 0 Answers

Input Manager: Gamepad axis only won't work (however buttons does) 0 Answers

Input Snap option not returning 0? 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