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 PvTGreg · Feb 28, 2014 at 10:24 PM · mouse-over

OnMouseOver how does it work?

Hi im trying to make it so when i right click a cube it loads the game scene but i cant get it to work can you guys help me out? ive also tried onmousedown but not matter where i click it loads the scene

 function OnMouseOver()
 {
    if(Input.GetMouseButtonDown(1))
    {
        Application.LoadLevel ("GameScene"); 
    }
 }
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 robertbu · Feb 28, 2014 at 10:38 PM 0
Share

Your script worked fine for me. $$anonymous$$ake sure the object has an enabled collider (should if it is a built-in cube). Put Debug.Log() statements in the code to see what is happening.

avatar image PvTGreg · Mar 01, 2014 at 08:55 AM 0
Share

Debug.Log("box is being clicked"); i put a debug.log but it shows nothing

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chris_taylor · Feb 28, 2014 at 10:45 PM

OnMouseOver will happen anytime the mouse goes over a collider and it will call the onmouseover on that collider. If you want it to be a click do OnMouseDown for a right click you will need to test what click happened so use Input.GetMouseButtonDown(1) inside the onmouseDown function or even on onmouseover

Comment
Add comment · Show 6 · 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 PvTGreg · Mar 01, 2014 at 08:54 AM 0
Share

ok i tried this but still when i rigt click it does nothing function On$$anonymous$$ouseDown() { if (Input.Get$$anonymous$$ouseButtonDown(1)) { Application.LoadLevel ("GameScene"); } }

avatar image Kiloblargh · Mar 01, 2014 at 09:13 AM 0
Share

You don't have a collider on the object.

avatar image PvTGreg · Mar 01, 2014 at 09:36 AM 0
Share

i do a box collider does it need to have is trigger checked? i aslo ahvea few bouncy scripts on it to work with my water

avatar image PvTGreg · Mar 01, 2014 at 11:43 AM 0
Share

ok i got it working by calling the onmosue down from the update funtioon but now no matter where i click it loads the scene

avatar image fafase · Mar 01, 2014 at 09:21 PM 0
Share

On$$anonymous$$ouseDown does not get called in the Update, it is an event method that is called automatically. In order to get the call, try this setup, place a cube, it should have the collider by default. Then attach that script:

 public class On$$anonymous$$ouseDownTrial:$$anonymous$$onoBehaviour{
     void On$$anonymous$$ouseDown(){
         print("Working?")
     }
 }

Now run the game and click on top of the cube, you should see the print.

To fully understand, place another cube, name it Cube2 and attach the script like this:

 public class On$$anonymous$$ouseDownTrial:$$anonymous$$onoBehaviour{
     void On$$anonymous$$ouseDown(){
         print("Clicking on" + name)
     }
 }

Now you see that the script prints different names. If you need to have different behaviours then create different scripts with the On$$anonymous$$ouseDown implemented differently.

You can also check for Input to see what button was pressed.

The other way consists in using Input and Raycast, it will result in the same thing but more code and maybe more control as well.

 public RayAndInputTrial:$$anonymous$$onoBehaviour{
     void Update(){
        if(Input.Get$$anonymous$$ouseButtonDown(1)){
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
              RaycastHit hit;
              if (Physics.Raycast(ray, out hit, 100)){
                 if(hit.collider.name = "Cube")print("Hit cube") 
              }
        }
     }
 }
Show more comments

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

Multiple Cars not working 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer

scripting help 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