1
Fork 0
mirror of https://github.com/Steffo99/bleach-beach.git synced 2024-12-04 19:04:19 +00:00
bleach-beach/Assets/Scripts/PlayerMovement.cs
2018-08-13 02:58:16 +02:00

44 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
private Rigidbody2D rb;
public GameObject hull;
public float horizontalShipSpeed = 5f;
public float verticalShipSpeed = 30;
public float maxJetFuel = 2f;
public float jetFuelRechargeSpeed = 0.1f;
private float jetFuel;
void Start () {
rb = GetComponent<Rigidbody2D>();
jetFuel = maxJetFuel;
}
void FixedUpdate () {
if (Input.GetAxis("Horizontal") < 0)
{
hull.transform.localScale = new Vector3(-1, 1, 1);
rb.AddForce(Vector2.right * -horizontalShipSpeed);
}
if (Input.GetAxis("Horizontal") > 0)
{
hull.transform.localScale = new Vector3(1, 1, 1);
rb.AddForce(Vector2.right * horizontalShipSpeed);
}
if (Input.GetAxis("Vertical") > 0)
{
if (jetFuel > 0f)
{
jetFuel = Mathf.Clamp(jetFuel - Time.deltaTime, 0, maxJetFuel);
rb.AddForce(Vector2.up * verticalShipSpeed);
}
}
else
{
jetFuel = Mathf.Clamp(jetFuel + Time.deltaTime, 0, maxJetFuel);
}
}
}