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:
parent
7ab2a3e247
commit
689c72c165
1 changed files with 29 additions and 0 deletions
29
Assets/Scripts/PlayerMovement.cs
Normal file
29
Assets/Scripts/PlayerMovement.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue