Well, logically I can think of how to check whether your mouse is over top of a mesh or other game object (cube for example). I know I could just use checks for where the x and y corrdinates are of the mouse, and then compare it to the x and y coords of the object, then check to see if they are equal. What I am wondering is, does the Unity API have something to do this already? What I want todo is move an object if it is clicked on then dragged. So does unity provide some function from the API?
Thanks,
Jedd
edit - Just realized this should be in the Scripting support forum, can a Mod please move this? Thanks
Add a script to your game object that has the OnMouseDown() function. Take a look at the Procedural Example from the Unity web site and look at the DragTransform.js script.
No it doesn’t. I don’t see where the import setting are. Also, I just tried adding a mesh collider to it by highlighting the mesh then going to Componet-> Physics → Mesh Collider. But it still doesn’t work :?
edit - I forgot to mention, when I add the script to it, a window pops up saying I will Lose my Prefab if i continue. I’m not sure what Prefab is, sooo…
if( Input.GetMouseButtonDown(0) ) { inside of OnMouseDown?
Just remove that part.
Also make sure the game object to which you are adding the script mesh collider is the same and actually contains the mesh renderer, and is not eg. just a node containing some children.
I did that because yoggy said in an above post… How can I tell the difference between just a node and an actual mesh renderer? I added a mesh renderer to it, if that is what you mean.
I have this code now
function OnMouseDown() {
isSelected = true;
renderer.material.color = highLightColor;
}
I think the problem is not your code. You need to have both a mesh renderer and mesh collider in your game object. The mesh renderer only controls what is displayed onscreen; the collider is what actually determines whether the mouse is over the object or not.
Do you have a renderer on the same object? What shader is it using? Does the material’s color turn red in the inspector? Any errors in the message bar?
Yes ( I think ). A new bar under mesh renderer appears saying “Default-Diffsue Instance (Material)
Shader: Diffuse
Main Color [shows red]
Base (RGB) [Box that says None]”
Yeah I’ll upload it in a little while. Right now I’ve got to sign off, so when I have time tonight I will. Should I delete anything to save space, since it’s 50 mb?
Oh, I should mention, when I upgraded to the Pro Version, then tried to import a file (the .blender) by: Asset->Import New Asset I recieved this error:
Should I report this as well? Seems to be an error in the actual source, that reports itself.
Do you have a collider on your camera? I found the mouseover functions do not work if there is a collider of sufficient size on the camera, blocking the detection since it’s basically ‘trapped’ inside another collision body.
Setting ‘Is Trigger’ to ON doesn’t change this.
Example, a camera with a sphere collider with 0.5 radius seems to ‘block’ the mouseover. Changing the radius to .05 doesn’t block it.