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 bmakloski · Jul 09, 2018 at 02:00 PM · scripting problem

OnMouseDown only works once

I have a GUI application where you can click on a panel and it'll take you to a new screen, then there is another button you can press to go back to the main menu. I am using OnMouseDown to go between the different scenes. I also have some DontDestroyOnLoad objects that are integral to the scene. When I go to the first scene, then back to the main menu, everything appears to be fine. However, I am unable to click on that panel again. Using the update function doesn't seem very likely because I have about 8 other panels. Here is what I'm doing right now:

 private void OnMouseDown()
     {
         if (this.gameObject.name == "Bay1")
         {
             Debug.Log("Bay1 Pressed");
             SceneManager.LoadScene(1);
         }
     }

Can anyone explain to me what is happening or what I'm doing wrong and some possible fixes? 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

Answer by swanne · Jul 09, 2018 at 02:49 PM

I've had a similar little issue recently which might help put you on the right track. I had multiple Panels and flicking back and forth between them caused frustrations when i previously interactable panel was no longer able to be interacted with. I found that the reason was down to additional panels blocking the raycast of the mouse click. I added a control into the functions of my scripts to modify the Sort Order of the panel and in some cases also modified the Block Raycast property. Have play with these values in the editor under play mode and see if you can click the item you wish to.

Comment
Add comment · Show 2 · 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 bmakloski · Jul 09, 2018 at 03:18 PM 0
Share

Is there any chance you still have that code you could show me as an example? And I'm not sure that is where my problem lies because my panels are definitely spaced out well enough that I don't think there would be any blocking. It feels more like the panel gets set to inactive or something when I return to the main menu. But I will definitely give this a try to see if it helps any.

avatar image swanne bmakloski · Jul 09, 2018 at 06:06 PM 0
Share

I've got the code I used and will try to explain any relevance to you. $$anonymous$$y game is a multiplayer game. The main game scene has a canvas, shared by all clients. Additionally, each client has a canvas for name input.

I used the component CanvasGroup to control visibility and raycast blocking. Here's the relevant code on the player:

  #region Canvas Groups
     public CanvasGroup postNameSelectGroup;
     public CanvasGroup playerSelect;
     #endregion
 
     public void Start()
     {
         if (!isLocalPlayer)
         {
             Debug.Log("This is not the local player");
             playerSelect.alpha = 0;
             return;
         }
 
         _gc = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
 
         //Trying to get around the interupted click thing
         numberOfPlayers = GameObject.FindGameObjectsWithTag("Player").Length;
         _playerCanvas.sortingOrder = numberOfPlayers;
 
         postNameSelectGroup.alpha = 0;
         postNameSelectGroup.blocksRaycasts = false;
 
         Debug.Log("PlayerScript: Yes, this is the local player");               
     }
 
 void postNameInput()
     {
         playerSelect.alpha = 0;
         playerSelect.blocksRaycasts = false;
         postNameSelect.text = pname;
         postNameSelectGroup.alpha = 1;
     }

Hope that helps a bit

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

151 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

Related Questions

Unity 8.1 How to get text via script 0 Answers

Is there a reason why Unity would be able to read one variable in a script and not another? 1 Answer

After exporting my project from my PC to my laptop the physics of my game work differently. 1 Answer

Left side panel in monodevelop 1 Answer

Script problem 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