Question by
uadmo · Jun 01, 2016 at 10:54 AM ·
movementgameobjectmousecoordinate-system
Move object like in scene mode
Hey everbody,
I try to move an object with an coordinate system like in the scene mode in unity. I've already get the movement in y- and x-direction. However, moving the object in z-direction with the mouse seems to be very difficult. In the scene mode you have to click on the "Z-Arrow" and move with the mouse in y-direction if the object is right in front of you. If the object is postponed you have to move the mouse diagonally.
My Code looks like as follows:
void Update()
{
.............
// Move in y-direction
if (selectedObject.name == "RedArrow" && Input.GetMouseButton(0))
{
Vector3 transY = new Vector3(0, Input.GetAxis("Mouse Y"), 0);
translationArrow.transform.position += transY * Time.deltaTime * speedTranslation;
previousObject.transform.position += transY * Time.deltaTime * speedTranslation;
}
// Move in z-direction
else if (selectedObject.name == "BlueArrow" && Input.GetMouseButton(0))
{
Vector3 transZ = new Vector3(0,0,Input.GetAxis("Mouse Y"));
translationArrow.transform.position += transZ * Time.deltaTime * speedTranslation;
previousObject.transform.position += transZ * Time.deltaTime * speedTranslation;
}
// Move in x-direction
else if (selectedObject.name == "YellowArrow" && Input.GetMouseButton(0))
{
Vector3 transX = new Vector3(Input.GetAxis("Mouse X"), 0, 0);
translationArrow.transform.position += transX * Time.deltaTime * speedTranslation;
previousObject.transform.position += transX * Time.deltaTime * speedTranslation;
}
}
I know the code of moving in z-direction doesn't meet my requirements but at least I can move it in the z-direction.
I would be very pleased if somebody could help me. Thanks.
Comment