I’m new at coding, so mind the basic stuff ;p
Basically i’m making a 2D Flash game but i cant get the movement right, it moves down just not up.
Heres the code:
using UnityEngine;
using System.Collections;
public class spaceshipBehaviour : MonoBehaviour {
public KeyCode moveUp;
public KeyCode moveDown;
public Rigidbody2D rb;
public float speed = 10f;
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(moveUp))
{
rb.velocity = new Vector2(rb.velocity.y, speed);
Debug.Log ("Moving Up");
}
else
{
rb.velocity = new Vector2(rb.velocity.y, 0);
}
if (Input.GetKey(moveDown))
{
rb.velocity = new Vector2(rb.velocity.x, speed *-1);
Debug.Log ("Moving Down");
}
else
{
rb.velocity = new Vector2(rb.velocity.x, 0);
}
}
}
Thanks for any help!
EDIT: It does the debug logs and stuff also so im not sure whats wrong with it ;s