A
A
Alex2020-02-24 12:52:06
Unity
Alex, 2020-02-24 12:52:06

How to get rid of the rotation code repetition?

My character rotates depending on which buttons are pressed. Because of this, there is a repetition of the same thing:

if(Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S))
        {
             angle = Quaternion.Euler(0, 45, 0);
        }
        else if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S))
        {
             angle = Quaternion.Euler(0, -45, 0);
        }
//  и так далее

What can be done to fix this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question