52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Saltosion.OneWeapon {
|
|
public class CameraFX : MonoBehaviour {
|
|
public Transform Player;
|
|
public Transform ShakeHandle;
|
|
public Transform CameraTransform;
|
|
public Camera Camera;
|
|
|
|
private Vector3 Offset;
|
|
|
|
private float ScreenShakeTime = 0.0f;
|
|
private float ScreenShakeIntensity = 0.0f;
|
|
private float TimeStopCooldown = 0.0f;
|
|
|
|
private void Start() {
|
|
Offset = CameraTransform.position;
|
|
CameraTransform.position = Player.position + Offset;
|
|
}
|
|
|
|
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;
|
|
CameraTransform.position = Vector3.Lerp(CameraTransform.position, TargetPosition, 5f * Time.deltaTime / Time.timeScale) + Offset;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|