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
1
Question by AceScottie · Mar 20, 2015 at 08:55 AM · uimouseover

UI window preventing OnMouseOver event on 3D Object

I have been working on this for a while now trying both raycast and OnMouseOver and i think i have missed a step somewhere along the way

I have a 3D model that is set to rotate. I am trying to say when the mouse is over the object (or a mesh collider) then stop rotating. However nothing i have tried in the last 3 hours has worked at all.

on my 3D model i have a mesh colider and a c# script called "rotate.cs"

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : MonoBehaviour {
     //private button = male;
     public bool rotate = true;
 
 
     void Start() {
 
     }
 
     void Update() {
         transform.position = new Vector3 (500, 0, 0);
 
         if (rotate == true) {
             transform.RotateAround (Vector3.one, Vector3.up, 20 * Time.deltaTime);
         } else {
             transform.RotateAround (Vector3.one, Vector3.up, 0);
         }
     }
     void OnMouseOver() {
         Debug.Log("Mouse Over");
         rotate = false;
     }
     void OnMouseExit() {
         Debug.Log("MouseOff");
         rotate = true;
     }
 }


Can someone go through step by step on how to get this working with either raycast or OnMouseOver event systems.

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

Answer by CHPedersen · Mar 20, 2015 at 09:05 AM

I just tested your script on a standard cube in an empty scene, and it behaves really odd. The cube rotates slowly but flickers violently as the call which sets transform.position fights the rotations.

The OnMouseOver and OnMouseExit methods execute perfectly fine. I did a minor change to your script, so now it looks like this:

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : MonoBehaviour
 {
     //private button = male;
     public bool rotate = true;
     
     void Start()
     {
 
     }
 
     void Update()
     {
         if (rotate == true)
         {
             transform.Rotate(Vector3.one, 20 * Time.deltaTime, Space.Self);
         }
     }
     void OnMouseOver()
     {
         Debug.Log("Mouse Over");
         rotate = false;
     }
     void OnMouseExit()
     {
         Debug.Log("MouseOff");
         rotate = true;
     }
 }

Try that. It removes the flickering and behaves the way you describe. You can use that as a starting point to move forward, at least.

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 AceScottie · Mar 20, 2015 at 09:50 AM 0
Share

Did you add anything else to the default cube, like colliders or other components ? i just created the cube and tried again with no luck. Also i have to use RotateAround with Vector3.up so it rotates around the up/down axis.

avatar image CHPedersen · Mar 20, 2015 at 09:56 AM 0
Share

Nothing. Started a new scene, then GameObject->3D Object->Cube. Then dragged above script onto that. I positioned the camera a little to look at the cube better, but that's it. When I start, the cube rotates slowly, unless the mouse hovers over it. The rotation starts/stops on mouse over.

But... I'm running Unity 4.6. $$anonymous$$aybe something got changed for Unity 5. Are you testing this on Unity 5?

avatar image AceScottie · Mar 20, 2015 at 10:04 AM 0
Share

yes its unity 5 i just started using it for work ill try it on a new scene,. it could be the UI stopping the mouse over events.

And thanks for the Help, really appreciate it

avatar image AceScottie · Mar 20, 2015 at 10:12 AM 0
Share

Ok just tested it, It is the UI getting in the way. I have a layout.cs which creates a UI window and loades a logout button and a inputTextFiele.

I believe the mouse is interacting with the window and not the cube. is there a simple way of getting the cube infront of the window so the mouse interacts with it ins$$anonymous$$d ?

 using UnityEngine;
 using System.Collections;
 
 public class layout : $$anonymous$$onoBehaviour {
 
     private Rect windowsRect = new Rect(0, 0, Screen.width, Screen.height);
     private string inputeString = string.Empty;
     private static int inputwidth = Screen.width/6;
     //private static int inputheight = inputwidth/3;
     private static int textsize = 0;
     private static int buttonHeight = Screen.height/24;
     private static int buttonWidth = Screen.width/12;
 
     void start() {
         if (Screen.height/15 <= inputwidth/4) {
             textsize = Screen.height/15 ;
         } else {
             textsize = inputwidth;
         }
 
     }
     
     
     void OnGUI()
     {
 
         GUI.Window (0, windowsRect, WindowFunction, "$$anonymous$$edic AL");
         GUI.skin.textField.fontSize = textsize;
 
              
         
     }
     
     void WindowFunction (int WindowID) {
         inputeString = GUI.TextField (new Rect (Screen.width - Screen.width / 3, 2 * Screen.height / 5, Screen.width / 3, Screen.height / 10), inputeString);
 
         if (GUI.Button (new Rect (buttonHeight/2, buttonWidth/4, buttonWidth, buttonHeight), "Logout")) {                
             Application.LoadLevel ("StartGUI");
         }
     }
     void Update () {
         
     }
 }
avatar image CHPedersen · Mar 20, 2015 at 10:36 AM 0
Share

Good find.

I'm not sure how to solve that one as my work hasn't invested in Unity 5 yet, so I have zero experience playing around with the new UI system, sadly. :/ But it looks to me like their UI mouse features are based on the same raycasting framework as the standard On$$anonymous$$ouseExit/Over etc. methods used with GameObjects that have colliders. If that is the case, then UI elements too must have colliders. Perhaps those can be disabled? Or perhaps there's a Layering system that allows you to ignore the UI layer?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Checking UI element beneath cursor in editor 2 Answers

4.6 New UI: MouseOver event/function needed 4 Answers

IPointerEnterHander only fires on click 0 Answers

GameObject rapidly changing position (flickering) 1 Answer

UI image with button component not tracking mouse correctly 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