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 UniqueMAX · Feb 03, 2015 at 05:17 PM · mousenot workingover

OnMouse--- functions not working

I've already checked many threads on this issue and tries everything suggested there. It just doesn't work. The idea: I have a group of 8 spheres attached to one cube positioned between them and 8 point lights attached to these spheres. During the game when player holds any button (let's say, LeftShift), this group appears at the current position of mouse and after that moves with the camera so that the cursor can move separately from the group. When the player releases LeftShift, the group disappears. Here's the code for this script and it works perfectly:

 public class GroupMove : MonoBehaviour {
 
     private Vector3 pos;
     private Vector3 oldpos;
     private bool appeared;
     public Camera cam;
     public GameObject Player;
 
     // Use this for initialization
     void Start () {
         oldpos=transform.position;
         appeared=false;
     }
     
     // Update is called once per frame
     void LateUpdate () {
         pos=new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
             if(Input.GetKeyDown(KeyCode.LeftShift) & appeared == false){
             transform.position=cam.ScreenToWorldPoint(pos);
             appeared=true;
         }
         else if(Input.GetKeyUp(KeyCode.LeftShift)){
             transform.position=oldpos;
             appeared=false;
         }
     }
 }

Next idea: during this group appearance all the lights are disabled. If player drags the mouse over any of the spheres, the attached light gets enabled. During the test all the lights are shut down so the Start () function works. However, they don't react to the mouse. The script is attached to each sphere, they all have colliders that don't cross each other or lay on each other in front of the camera view. I even tried to separate them from each other and from their lights really far - no result. Tried functions Over, Enter, Exit, Click. Also added debug command to know wether or not they detect the mouse. Empty result. The sphere code:

public class ButtonCheck : MonoBehaviour {

 public Light BtnLight;
 void Start () {
     BtnLight.enabled=false;
 }

 void OnMouseOver () {
     Debug.Log ("Clicked!");
     BtnLight.enabled=true;
 }
 

}

I really need help on this one cause otherwise the project can be simply thrown away.

Comment
Add comment · Show 5
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 Mmmpies · Feb 03, 2015 at 05:18 PM 0
Share

Tried that light script and it works. When the mouse goes over the sphere the light I setup works. So are you getting any errors in the console?

avatar image UniqueMAX · Feb 03, 2015 at 05:19 PM 0
Share

The console is empty and shows nothing. Could you please share a screenshot of how you positioned the group objects?

avatar image Mmmpies · Feb 03, 2015 at 05:43 PM 0
Share

Sure @Unique$$anonymous$$AX, I only added 1 sphere and 1 pointlight just above as we just need to work out what's wrong.

Hierarchy

and then the Inspector for the sphere that has the script on it:

Inspector

Press play and move the mouse over the sphere and the light does com on.

EDIT

This is the script just for completeness:

 using UnityEngine;
 using System.Collections;
 
 public class ButtonCheck : $$anonymous$$onoBehaviour {
     
     public Light BtnLight;
     void Start () {
         BtnLight.enabled=false;
     }
     
     void On$$anonymous$$ouseOver () {
         Debug.Log ("Clicked!");
         BtnLight.enabled=true;
     }
 }
sphereinspector.png (48.5 kB)
spherelight.png (3.7 kB)
avatar image skunity3D · Feb 03, 2015 at 06:31 PM 0
Share

$$anonymous$$ake sure your colliders are enabled to get the On$$anonymous$$ouseOver function to be fired.

avatar image UniqueMAX · Feb 03, 2015 at 07:07 PM 0
Share

found the problem. $$anonymous$$y spheres were attached to the center cube to keep them together. They can't recieve On$$anonymous$$ouse functions as childs, as it seems.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · Feb 03, 2015 at 07:20 PM

I don't believe that's true. I created a new sphere/light and a new cube. I kept the scripts on the spheres (one on each) and made them children of the cube:

2ChildObjects

matched the light to the sphere script slot on both spheres and also added the OnMouseExit() to switch off the light.

Both lights work perfectly, I'm using unity free/indie and version 4.6.1f1.

EDIT

And Here is a link to a video showing it working

 using UnityEngine;
 using System.Collections;
 
 public class ButtonCheck : MonoBehaviour {
     
     public Light BtnLight;
     void Start () {
         BtnLight.enabled=false;
     }
     
     void OnMouseOver () {
         BtnLight.enabled=true;
     }
 
     void OnMouseExit() {
         BtnLight.enabled=false;
     }
 }



2childobjects.png (2.2 kB)
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 skunity3D · Feb 04, 2015 at 01:18 PM

Hello Mmmpies,

I would like you to see that its not about the nesting of gameobjects, its about the colliders. I have used your script "ButtonCheck" in the following image.

alt text

There are two setups :

Setup 1. Cube with two child spheres and the cube has a collider which has its box collider size values set to 1, 1, 1. These are the ones in row 1. So in this set up when you rollover onto the sphere the light shows up as intended, and you can see it in first two images in the collage above.

Setup 2. Cube with two child sphers but here this cube has a collider which has it box collider size values set to 10, 2, 5. These are the ones in row 2. But now when you rollover to two spheres below nothing happens as you can see in the third (image top right) in the collage above.

The reason is when see the fourth image in bottom left of the collage, you would realize that the cube's box collider overlaps the its child spheres hence their sphere colliders are encapsulated as well. Thus the OnMouseOver script on the spheres wont work. But if you disable the Box collider and then check, OnMouseOver script will start working as intended on the spheres in setup2.

So UniqueMAX, the spheres being child of cube is not the problem, just check whether their (sphere's) collider are not being obstructed by any other collider towards the camera.

Regards,


overlap.png (234.2 kB)
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 Mmmpies · Feb 04, 2015 at 01:34 PM 0
Share

To be fair @skunity3D I really didn't think it was about nesting, that's the exact point I was making to @Unique$$anonymous$$AX, and you're right it could be an extended collider on the parent but it wouldn't have to be a parent.

Any collider from any object that extends over the collider on the sphere would cause the issue. You can test it yourself, just create cube and a sphere objecte and put an On$$anonymous$$ouseOver script on the sphere to Debug.Log out a message and extend the cubes box collider until it covers half the sphere.

you'll see, even if not a parent, the collider will block the half of the sphere that it covers.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Inconsistent Input.GetMouseButtonDown Detection 0 Answers

when mouse pass over a button,the console print some content 1 Answer

Change GUI on mouse over 1 Answer

Getting mouse over GUI event 0 Answers

Mouse Over Inconsistency 0 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