Jump to content
Unity Insider Forum

Recommended Posts

Mein code ist so:

    void Update()
    {
        rb2D.velocity = new Vector2(0, 0);

        if (Input.GetKey(KeyCode.A))
        {
            rb2D.velocity = new Vector2(-6, 0);
        }

        if (Input.GetKey(KeyCode.D))
        {
            rb2D.velocity = new Vector2(6, 0);
        }

wen ich aber das spiel starte wir die D taste bevorzugt.

wie kann ich das fixen?

Link to post
Share on other sites
vor 1 Minute schrieb MichaelH:

Dann wird allerdings die A-Taste bevorzugt. Man kann halt nicht in zwei Richtungen gleichzeitig.

Na klar. Entweder oder. Vielleicht will er auch, dass es dann gar keine Bewegung gibt? 

 

Christoph 

Link to post
Share on other sites

Vermutlich!

Dann halt

var direction = 0f;

if (Input.GetKey(KeyCode.A))
{
  direction -= 6;
}

if (Input.GetKey(KeyCode.D))
{
  direction += 6;
} 

rb2D.velocity = new Vector2(direction, 0);

 

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...