I have a sphere in my program that you click on once. After the click an object is instantiated and the sphere’s transform.localScale is reduced by 10 (originally 100). After the scale down takes effect I cannot click on the object again. I’ve tried detecting the mouseButton input after both OnMouseEnter and OnMouseOver. My most recent attempt is using a raycast here:
Does it hit another collider? And what you expecting to happen? It looks like nothing. Just do prints to se what you ray is hitting and what portion of the function the ray is entering.
This code is inside the Update function. So if I press the mouse button a ray is cast and the object that is hit is taken. If the object is anything except the sphere it is ignored. After the first cast it ignores the sphere as well and I’d like to know why.
I say check the collider. In my game I was running into a similar issue. Turns out my ray was not hitting the desired collider because another one was in the way of it.
is the node at position (0,0,200) somehow between the camera and the nucleus?
You could try using a RaycastAll until you sort out why it isn’t hitting the nucleus collider directly. You just have to iterate over all the hits to see if it’s even being hit.
You could try limiting your raycast to a specific layer and put nucleus objects on that layer instead of trying to check a tag.
I’ll check the collider from the raycast and if that doesn’t work I’ll put them in layers. @ Democre … no the nucleus is directly at Vector3.zero so the node is clear of the nucleus
One other thought, what object is this script attached to? Is it meant for the local scale of that object to be reduced? Or should you be changing grabbed.transform’s local scale?
The script is attached to the nucleus in the center of the screen. So either way would work. Do you think that having it attached to the grabbed object is causing the problem?
If this script is on the nucleus object, and you want to respond to clicks on the nucleus object, you could simplify this by using the OnMouseUpAsButton event, and skipping the raycast altogether.
I have discovered the issue. The OnMouse functions and raycast keep failing because something is setting my nucleus layer to ignore raycasts after the first click. I have my nodes using raycasting to determine drag and drop positions, and that might be the problem. So…
Now I can move my nucleus to a different layer and hope that works OR find another way to do drag and drop for 3d objects.
Thanks for all your help and I’ll let you know what solution I come up with.