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 mrmeizongo · Aug 13, 2018 at 01:11 PM · uigameobjectscreen

I can't get a button to register a touch and execute.

So I have this function to make my character jump after a tap.

 private void Jump()
     {
         if(Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             
             if(touch.phase == TouchPhase.Began)
             {
                 body.AddForce(Vector3.up * jumpForce * 2);
 
                 if (!jumpSound.isPlaying)
                 {
                     jumpSound.Play();
                 }
             }
         }
     }

And then I also a button on the screen to pause game and display the menu. The problem here is the menu button does not register the touch while the player is active in the game. When the player dies I set it's gameObject.SetActive(false) and that is when the menu button works. It only registers the touch and executes when the player gameObject is not in the game scene anymore. Can anybody tell me what I'm doing wrong?

Comment
Add comment · Show 4
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 mrmeizongo · Aug 13, 2018 at 01:27 PM 0
Share

The player still jumps when I tap on the menu button. The menu button only works when the player dies and it's set to inactive in the scene. Just to make it a little more clearer.

avatar image mrmeizongo · Aug 13, 2018 at 01:48 PM 0
Share

On further testing it appears that the menu button requires the player to be active and die before it executes. I manually deactivated the player gameObject to try it and it still didn't work but it works when the player was active in the scene and dies. Just for reference here is the button script

 public void ShowPause$$anonymous$$enu()
     {
         if(playerScript.IsDead() == false)
         {
             Time.timeScale = 0;
         }
 
         ui$$anonymous$$anager.Show$$anonymous$$enu();
         ui$$anonymous$$anager.HideTitleScreen();
     }

   

It is attached to the onClick function in the inspector via the Game$$anonymous$$anager gameObject which has this piece of code in in a script attached to it.

avatar image ilyavitek · Aug 20, 2018 at 07:22 AM 0
Share

I think it´s hard to detect the problem with all this info, maybe you can provide a little bit more and I can try to go deeper in the problem because now it could be a lot of things which stop your code.

avatar image DKaraush · Aug 20, 2018 at 04:04 PM 0
Share

Try to check checkbox in button's inspector (don't remember which one, i'm on mobile now)

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

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

UI elements following GameObjects (3d world) 1 Answer

Trying to delay movement of a GameObject 1 Answer

How do I get my object to trigger a UI screen when it touches another object? 1 Answer

one button to hide and unihed gameobjects 0 Answers

Unity ads , can't we show video by clicking a button? 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