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 Sad_Man30 · Sep 01, 2020 at 11:56 AM · 2d gametopdown

how to stop the movement of the player when a dialogue box appear?

alt text

i want to dissable the movement when a dialogue box appear or make the dialogue dissapear when leaving the trigger area help pls

my scrpit of the trashcan

  public class Clickable : MonoBehaviour
  {
      public bool triggered;
      public Dialogue dialogue;
  
      void OnMouseDown()
      {
          if (triggered)
          {
              FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
          }
      }
  
      void OnTriggerEnter()
      {
          if (other.gameObject.CompareTag("Player"))
          {
              triggered = true;
          }
      }
      void OnTriggerExit()
      {
          if (other.gameObject.CompareTag("Player"))
          { 
              triggered = false; 
          }
      }
  }

help2.png (269.0 kB)
Comment
Add comment · Show 3
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 dukious25 · May 27 at 09:15 AM 0
Share

sir, Can I see your dialog script I'm making the same thing but the tutorial that I watch is using space to continue not by touch how do you make it touch sir? @Sad_Man30 thank you for your response.

avatar image Sad_Man30 dukious25 · May 27 at 04:10 PM 0
Share

that "touch here to continue" is a button

avatar image dukious25 · May 27 at 04:17 PM 0
Share

Oh it just a button, I thought you replace the that keycode.space by some touch thing, thank you sir

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by oStaiko · Sep 02, 2020 at 05:50 AM

@ShadyProductions' answer was close, but had some big issues involved. It immediately disabled player controls on collision instead of when it was clicked on, and it relied on the player walking out of the collider to re-enable their controls, which... wouldn't be possible.


For starters, (continuing from the previous answer), move the enabled flag to your PlayerControls script, or whatever else you call that script. This is mostly for good-practice reasons to keep it organized.

It should look something like this:

 public class PlayerControls : MonoBehaviour
 {
     public static bool playerControlsEnabled = true;

     HandleMovement()
     {
         if (playerControlsEnabled)
         {
              // Player controls in here
         }
     }
 }



Here's what your Clickable class should look like:

  public class Clickable : MonoBehaviour
  {
      public bool playerInRange;
      public Dialogue dialogue;
      
      void Activate()
      {
          if (playerInRange)
          {
              FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
              PlayerControls.playerControlsEnabled = false;
          }
      }
  
      private void OnTriggerEnter2D(Collider2D other)
      {
          if (other.gameObject.CompareTag("Player"))
          {
              playerInRange = true;
          }
      }

      private void OnTriggerExit2D(Collider2D other)
      {
          if (other.gameObject.CompareTag("Player"))
          {
              playerInRange = false;
          }
      }
  }



Next you're going to want your DialogueManager script to re-enable the players controls whenever the dialogue box closes. Just access the bool the same way and set it to true again, and it should all be fine.

That step heavily depends on how that script works, but since we can't see it, it's up to you to figure that part out.

Comment
Add comment · Show 5 · 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 ShadyProductions · Sep 02, 2020 at 07:09 AM 0
Share

Nothing wrong with my answer, I never disabled movement in my pseudo code, that is up to the user himself. He only specified to disable player controls and I gave him a template to do it. Not going to write the code for him :)

avatar image Sad_Man30 ShadyProductions · Sep 02, 2020 at 09:15 AM 0
Share

i specifically say "when a dialogue box appear"

avatar image Sad_Man30 · Sep 03, 2020 at 03:51 AM 0
Share

thank you for the answer i finally understand it and your code work ty

avatar image dukious25 · May 27 at 09:27 AM 0
Share

sir, Can I see your dialog script I'm making the same thing but the tutorial that I watch is using space to continue not by touch how do you make it touch sir? @Sad_Man30 thank you for your response.

avatar image Caeser_21 dukious25 · May 27 at 07:03 PM 0
Share

I'm pretty sure a question similar to this has been answered (Try searching how to get mouse input on google) but if you have a question don't comment on an old thread make a new question...

avatar image
1

Answer by ShadyProductions · Sep 01, 2020 at 12:16 PM

You got all this way and don't know how to add a simple if check like this, must of been some good copy pasting :D

Here is some rough pseudo code, but it should point you in the right direction.

 public static bool PlayerControlsDisabled = false;

 private void OnTriggerEnter(Collider other)
 {
     PlayerControlsDisabled = true;
 }

 private void OnTriggerExit(Collider other)
 {
     PlayerControlsDisabled = false;
 }

You can then in your PlayerControls check if the bool is true or not

 if (yourscriptname.PlayerControlsDisabled == false)
 {
     // Player controls in here
 }
Comment
Add comment · Show 3 · 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 Sad_Man30 · Sep 02, 2020 at 04:24 AM 0
Share

it's saying to me that PlayerControlsDisabled is assigned but it's value is never used this is what i did

 public class Clickable : $$anonymous$$onoBehaviour
 {
     public bool triggered;
     public Dialogue dialogue;
     public static bool PlayerControlsDisabled = false;
     
     void On$$anonymous$$ouseDown()
     {
         if (triggered)
         {
             FindObjectOfType<Dialogue$$anonymous$$anager>().StartDialogue(dialogue);
         }
     }
 
     private void OnTriggerEnter2D(Collider2D sad)
     {
         if (sad.gameObject.CompareTag("Player"))
         {
             triggered = true;
             PlayerControlsDisabled = true;
         }
     }
     private void OnTriggerExit2D(Collider2D sad)
     {
 
         if (sad.gameObject.CompareTag("Player"))
         {
             triggered = false;
             PlayerControlsDisabled = false;
         }
     }
 }

and in my player script no error when i added it

avatar image ShadyProductions Sad_Man30 · Sep 02, 2020 at 07:13 AM 0
Share

https://www.c-sharpcorner.com/UploadFile/e9fdcd/basics-of-C-Sharp/

learn first then apply, not the other way around.

avatar image Sad_Man30 · Sep 02, 2020 at 09:13 AM 0
Share

i happen to make the code you give run but it did not even disable anything, it will only disable when i change the code to true

sad

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

178 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

Related Questions

2D Rotation for aiming problem 1 Answer

2d top-down rpg direction check 1 Answer

How to get an enemy to go to a location and then return. 1 Answer

Prefab to a tile script 0 Answers

2D character Animation-controller 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