1
Fork 0
mirror of https://github.com/Steffo99/bleach-beach.git synced 2024-12-04 19:04:19 +00:00

Add player movement

This commit is contained in:
Steffo 2018-08-11 11:47:22 +02:00
parent 7ab2a3e247
commit 689c72c165

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody2D rigidbody;
public float horizontalShipSpeed = 35;
public float verticalShipSpeed = 10;
void Start () {
rigidbody = GetComponent<Rigidbody2D>();
}
void FixedUpdate () {
if (Input.GetKey(KeyCode.LeftArrow))
{
rigidbody.AddForce(Vector2.left * horizontalShipSpeed);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rigidbody.AddForce(Vector2.right * horizontalShipSpeed);
}
if (Input.GetKey(KeyCode.UpArrow))
{
rigidbody.AddForce(Vector2.up * verticalShipSpeed);
}
}
}