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 /
  • Help Room /
avatar image
0
Question by $$anonymous$$ · Feb 28, 2020 at 03:43 PM · functiondisablepause menu

Can i disable a function in another script?

Idk how to explain, i made a button that pauses the game (left top corner) it`s working good but the problem is that when i touch that button, my player object also gets the touch input for his script(it`s jumping) Here is my player script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class Player : MonoBehaviour
 {
     public Rigidbody2D rb;
    
     public int health=1;
 
    
     public GameObject gameOver;
     public Animator anim;
 
 
 
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
     }
     
 
 
     void Update()
     {
         
         if (health <= 0)
         {
             gameOver.SetActive(true);
             Destroy(gameObject);
         }
 
         if (health == 1)
         {
             anim.Play("Player1");
         }
         else if (health==2)
         {
             anim.Play("Player_shield");
         }
         
             if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetMouseButton(0))
             {
 
                 anim.SetFloat("runMultiplier", 1f);
 
                 rb.velocity = new Vector2(rb.velocity.x, 7);
                 rb.velocity = new Vector2(rb.velocity.x, 7);
 
             }
             else
             {
                 
                 anim.SetFloat("runMultiplier", 0.7f);
             }
         
         
     }
 
    
 }
 



and here is my pause button script :

 using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.SceneManagement;
     using UnityEngine.UI;
     public class PauseButton : MonoBehaviour
     {
         public GameObject PauseMenuUI;
        
         public void Pause()
         {
        
             PauseMenuUI.SetActive(true);
             Time.timeScale = 0f;
             
         }
     }
     

 

So when i press the pause button, the player also jumps and when i exit the pause menu it is going up(continues the movement input), i thought about disabling the update function on player whenever i press the pause button, but i don`t know how and not sure if it`ll work. Can you give me some tips? Thank you!

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

Answer by tormentoarmagedoom · Feb 29, 2020 at 01:23 AM

Hello.

You dont need to disable anything.

Just need to be sure at the touch function to be sure you are not touching a UI element. something with this structure:

 if (Input touch)
  {
   if (Touching UI)
   {
   nothing (or not)
   }
   else
   {
   Jump
   }
 }

Check this post: https://answers.unity.com/questions/1115464/ispointerovergameobject-not-working-with-touch-inp.html?_ga=2.70265235.20869102.1582893140-1660236971.1528636420

Bye!

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 $$anonymous$$ · Feb 29, 2020 at 06:16 PM 0
Share

Thanks, i found this function using UnityEngine.EventSystems;

 /// <summary>
 /// Checks if the pointer, or any touch is over (Raycastable) UI.
 /// WARNING: ONLY WOR$$anonymous$$S RELIABLY IF IN LateUpdate/LateTickable!
 /// </summary>
 private bool IsPointerOverUIObject()
 {
     if (EventSystem.current.IsPointerOverGameObject())
         return true;
  
     for (int touchIndex = 0; touchIndex < Input.touchCount; touchIndex++)
     {
         Touch touch = Input.GetTouch(touchIndex);
         if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
             return true;
     }
  
     return false;
 }

it`s checking if it`s an UI touched and it`s working with this, ty.

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

197 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 avatar image avatar image avatar image avatar image 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 to disable mouse lock script when returning to main menu 1 Answer

C# Disabling Camera moving while in Pause Menu 1 Answer

How can i enable and disable a void function on the update function? 1 Answer

How to make a UI Image appear/disappear? 2 Answers

Problem in disabling button and error in the statement 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