- Home /
How to Select objects and move and rotate them on the x,y,z axis.
Hi, I was wondering how I could move objects on the x,y,z axis in my game. Like when you select a object a 3 arrows will appear to show t x,y,z axis same with rotation it but only with rings around it. If you could help me I would appreciate it a lot.
Answer by lodendsg · Dec 02, 2019 at 08:08 AM
this should be easy enough.
1st you would want to make your UI element you could do this simply as a world canvas or ... well you have loads of options so I will leave that to you for now.
2nd you want to handel the on click so you know when the object is selected. If this is a 3D object which I assume it is you will need 2 things for this to work.
1 = A collider on the object
2 = A Physics Ray Caster on the camera
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.PhysicsRaycaster.html
Doing that you can now use the MonoBehaviour's mouse events much like you would with a UI object e.g. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseEnter.html You would use that to show or hide your UI element as noted above ...
So for example you migh thave the UI element be hiden by default and to show when mouse over, then you can use the UI element to know which action the player wants to perform e.g. if they mouse down on the up arrow aka Y axis element then they want to transform on the y and you can apply the mouse Y deleta on the selected objects Y axis.
Answer by rootbeer12 · Dec 02, 2019 at 06:03 PM
I don't understand it completely Cause I'm new to unity. I got to the adding the collider and the physics ray caster. But how do I add the on mouse enter on the ui? Cause it needs a renderer to work amd the ui doesn't have a renderer a mesh. I've tried putting the script on the ui button and then adding my mesh from the object to it but it does not work. The only way I've found it to work is by adding the on mouse look script to the game object itself is that what you meant?
For UI you need to add the interfaces
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EventSystems.IPointerClickHandler.html
The above is for Pointer Click but there are interfaces for enter, exit, etc.
Alright so I create 3 buttons with arrows for the x y z axis add a collider and the on mouse enter script to say a block add the pointer click to the ui buttons then what. I'm so sorry for the inconvenience
Thought I had already replyed to this but if not
You can now handle the click on the object to show the gimble (the UI elements) You can now handle the click on parts of the gimble to start the transform process e.g. On $$anonymous$$ouse Down on the Y axis UI element you would start moving the object according to the mouse's y delta and mouse up on teh Y axis UI element you would stop
Its worth noting that there are other was of handling this I was really only trying to help you get to the point of understanding how you would capture mouse event data on the 3D object and the UI elements that should be all you need to build out a transform tool. If your looking for something more specific than that I think you are looking for a ready made asset that will do it for you. There are likely a few on the asset store or you can contract someone to build you one. we (Heathen Engineering) do contract work and you will find others as well via Unity Connect I think its called.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215549im_/https://answers.unity.com/themes/thub/images/avi.jpg)