Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 laurienash · Apr 13, 2015 at 03:07 PM · keypress

MouseButtonDown not being stored between scenes

Hi, In my game when a player presses the right mouse button in scene 0, I want scene 1 to load. (and the mouse button is kept down). When the mouse button is released in scene 1, I want scene 0 to load again.

The first switch is easy enough - but I just can't get the switch back working.

It seems that unity doesn't store which key has been pressed between scenes, so when I use

  if (Input.GetMouseButtonUp(1))

in scene 1 to load scene 0 again nothing happens.

I tried attaching a script to a gameobject which isn't destroyed between scenes and wrote this

  function Update () {
  
      if (Input.GetMouseButtonDown(1))
      {
 Debug.Log ("mousedown");
       
        
      }
      
        if (Input.GetMouseButtonUp(1))
      {
 Debug.Log ("mouseup");
       
           
      }
  }

To see if anything would show on the console - but it isn't recognising that the mouse button is released.

Does anyone know how I would go about doing this?

Would it be possible to simulate the right mouse button down at the start of scene 1 in code so when it is released this is recognised - or is what I'm trying to do really not possible?

Best, Laurien

Comment
Add comment · Show 2
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 hexagonius · Apr 13, 2015 at 03:40 PM 0
Share

If Up and Down are not delivered between scenes properly then you could do your own logic with Input.Get$$anonymous$$ouseButton(0). It returns true as long as it's held down. In Scene 0, check for (the first?) true and switch scenes. In scene 1 check for false.

avatar image laurienash · Apr 13, 2015 at 06:25 PM 0
Share

Hi - so I tried this out: but even though in scene 1 the right mouse button is still held down, it instantly loads scene 0 again.

I think each scene resets what keys are up and down so that they're all up - so as soon as scene 1 is loaded - it thinks the button has been released when it hasn't.

    public var loaded : boolean = true; 
     
     function Update () 
     {
         if(loaded == true)
         {
             if(Input.Get$$anonymous$$ouseButton(1) == true)
             {
                     loaded = false;
                     LoadDelay();
             }
         }
     }
     
     function LoadDelay()
     {
         yield WaitForSeconds(.5);
         if(Input.Get$$anonymous$$ouseButton(1) == true)
         {
             Application.LoadLevel(1);    
         }
         loaded = true;
     }
 
 
 
 public var loaded : boolean = true; 
 
 function Update () 
 {
     if(loaded == true)
     {
         if(Input.Get$$anonymous$$ouseButton(1) == false)
         {
             loaded = false;
             LoadDelay();
         }
     }
 }
 
 function LoadDelay()
 {
     yield WaitForSeconds(.5);
     if(Input.Get$$anonymous$$ouseButton(1) == false)
     {
         Application.LoadLevel(0);
     }
 
     loaded = true;
 }


2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Yasser Jaffal · Apr 13, 2015 at 04:54 PM

I guess that the internal state of mouse button in Unity is reset on scene load, so it does not matter in which state the mouse button is when the new scene is loaded.

Comment
Add comment · 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
0

Answer by adder_be · Apr 14, 2015 at 03:36 PM

After some research I've concluded that unity's Input class ignores input that begun before the start of the scene. See:

  • http://www.reddit.com/r/Unity3D/comments/11zpj6/how_to_use_applicationloadlevel_without_resetting

  • http://answers.unity3d.com/questions/918300/loadlevel-resets-all-input-to-0-disastrous.html

I would suggest looking into different ways to achieve what you want. zaikman raises a valid point in his post on the reddit question above: 'Do you really need an individual scene for every room/gameview you have?'

In this particular case you could - for example - have the content of both your scene 0 and scene 1 in one combined scene, at different world positions and move the camera between these positions according to the user's mouse input. Another option would be to activated and deactivate the objects you want to display/hide.

You should try some things and use the one you feel most comfortable with.


If you still want to keep things in different scenes: other users have managed to work around the issue by using LoadLevelAdditive(), might be worth investigating that.

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 Shadoninja · Oct 20, 2018 at 05:34 PM 0
Share

There are plenty of valid reasons to have each room be its own scene. It may not be the right way for everyone, but reading input between scenes should not be a request that a creator has to defend.

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

21 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

Related Questions

How could i execute a command move for a fighting game? 3 Answers

Best way to handle keypress? 3 Answers

Odd input glitch 2 Answers

unity3d android gui flickering rendertexture GL.Clear 0 Answers

Scoring system by pressing a series of particular keys 2 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