1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/BrakeBarController.cs

35 lines
949 B
C#
Raw Permalink Normal View History

using System.Collections;
2018-04-22 20:18:18 +02:00
using System.Collections.Generic;
using UnityEngine;
public class BrakeBarController : MonoBehaviour {
2018-04-23 23:07:39 +02:00
float maxRotation = 129;
float currentRotation = 0;
2018-04-22 20:18:18 +02:00
private Player player;
// Update is called once per frame
void Update() {
2018-04-23 23:07:39 +02:00
float offset = 0;
2018-04-22 20:18:18 +02:00
// if player alive and spawned
2018-04-23 23:07:39 +02:00
if (player != null) {
offset = CalculateOffset();
2018-04-22 22:07:57 +02:00
}
2018-04-23 23:07:39 +02:00
else {
offset = -currentRotation;
}
currentRotation += offset;
gameObject.transform.Rotate(Vector3.forward, -offset);
}
2018-04-22 22:07:57 +02:00
2018-04-23 23:07:39 +02:00
private float CalculateOffset() {
2018-04-23 23:14:41 +02:00
return (maxRotation * (player.GetComponent<PlayerMovement>().GetBrakeTime() / player.GetComponent<PlayerMovement>().maxBrakeTime)) - currentRotation;
2018-04-22 20:18:18 +02:00
}
2018-04-22 22:07:57 +02:00
public void SetPlayer(Player ply) {
player = ply;
2018-04-23 23:07:39 +02:00
maxRotation = 129;
currentRotation = 0;
}
}