N
N
notahuman2020-07-22 21:26:47
Unity
notahuman, 2020-07-22 21:26:47

How to rotate an object with the mouse?

Hello! I have such a problem that I have a beam and I need to be able to rotate it along the Z (Left / Right) axis when holding the left mouse button. But for how much my programming level is the most basic, I hope you can help me. I have a 2D game.
Please do not say that you can use this or that, as I will not understand anything. I would be very grateful for the links to the video tutorials.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zZaKko, 2020-07-23
@zZaKko

There are such things as Input and GetAxis. Here you need to learn with them) There are many videos on the Internet, choose which one suits you) You can build on this:

void FixedUpdate(){
if(Input.GetKey(KeyCode.Mouse0)) //если зажата ЛКМ
{
obj.transform.rotate(0f,0f, Input.GetAxis("Mouse X")); //обьект вращаеться по z относительно перемещения мышки по вектору x
}
}

ps do not be lazy to google, everything will always not be decided for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question