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.
↧