BloodAndGore/Assets/Scripts/Effects/CameraFX.cs

55 lines
1.9 KiB
C#
Raw Normal View History

2019-08-04 18:35:08 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-08-14 16:17:48 +02:00
namespace Saltosion.OneWeapon.Effects {
2019-08-04 18:35:08 +02:00
public class CameraFX : MonoBehaviour {
public Transform Player;
public Transform ShakeHandle;
2019-08-07 20:03:51 +02:00
public Transform CameraTransform;
public Camera Camera;
2019-08-04 18:35:08 +02:00
private Vector3 Offset;
private float ScreenShakeTime = 0.0f;
private float ScreenShakeIntensity = 0.0f;
private float TimeStopCooldown = 0.0f;
2019-08-21 22:14:23 +02:00
private Vector3 DummyPosition;
2019-08-04 18:35:08 +02:00
private void Start() {
2019-08-07 20:03:51 +02:00
Offset = CameraTransform.position;
2019-08-21 22:14:23 +02:00
DummyPosition = Player.position + Offset;
2019-08-04 18:35:08 +02:00
}
private void Update() {
if (TimeStopCooldown > 0) {
TimeStopCooldown -= Time.deltaTime / Time.timeScale;
if (TimeStopCooldown <= 0) {
Time.timeScale = 1.0f;
}
}
Vector2 TargetPosition = (Player.position * 2f + Camera.ScreenToWorldPoint(Input.mousePosition)) / 3.0f;
2019-08-21 22:14:23 +02:00
DummyPosition = Vector3.Lerp(DummyPosition, TargetPosition, 5f * Time.deltaTime / Time.timeScale) + Offset;
CameraTransform.position = new Vector3(Mathf.Floor(DummyPosition.x * 100) / 100, Mathf.Floor(DummyPosition.y * 100) / 100, Mathf.Floor(DummyPosition.z));
2019-08-04 18:35:08 +02:00
if (ScreenShakeTime > 0) {
ScreenShakeTime -= Time.deltaTime;
ShakeHandle.localPosition = new Vector2(Random.value, Random.value) *
Mathf.Pow(ScreenShakeTime, 2f) * ScreenShakeIntensity * Random.value;
}
}
public void StopFor(float seconds) {
Time.timeScale = 0.05f;
TimeStopCooldown = seconds;
}
public void ScreenShake(float intensity) {
ScreenShakeIntensity = intensity;
ScreenShakeTime = 0.2f;
}
}
}