Quantcast
Channel: Questions in topic: "left"
Viewing all articles
Browse latest Browse all 135

Rigidbody2d Moving up and Down but not left and right

$
0
0
Hello guys, Fresh unity user here, My RigidBody2D (pong game) is correctly moving up and down, but not left and right. The code seems simple, but i can't understand why it's not moving. I have set the controls to the correct KeyCode. Can you explain what mistake i have made? There is my code : var moveUp : KeyCode; var moveDown : KeyCode; var moveLeft : KeyCode; var moveRight : KeyCode; var speed : float = 12; function Update () { if (Input.GetKey(moveUp)) { GetComponent.().velocity.y = speed; } else if (Input.GetKey(moveDown)) { GetComponent.().velocity.y = -speed; } else if (Input.GetKey(moveLeft)) { GetComponent.().velocity.x = -speed; } else if (Input.GetKey(moveRight)) { GetComponent.().velocity.x = speed; } else { GetComponent.().velocity.y = 0; } GetComponent.().velocity.x = 0; } Thanks a lot.

Viewing all articles
Browse latest Browse all 135

Trending Articles