new VO, Scroll. Cave, devil spider fix , new Cover gaze Roots and FX
This commit is contained in:
@@ -1,31 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
public class CameraShaker : MonoBehaviour
|
||||
{
|
||||
public float m_amplitude = 0.1f;
|
||||
public float m_time = 1.0f;
|
||||
Vector3 m_position;
|
||||
// Start is called before the first frame update
|
||||
[Header("Shake Settings")]
|
||||
public float amplitude = 0.1f; // Si³a drgania
|
||||
public float duration = 1.0f; // Czas trwania drgania
|
||||
public float frequency = 20f; // Prêdkoœæ drgania
|
||||
|
||||
[Header("Shake Curve")]
|
||||
public AnimationCurve shakeCurve = AnimationCurve.EaseInOut(0, 1, 1, 0); // Krzywa efektu drgania
|
||||
|
||||
private float shakeTime = 0f;
|
||||
private Vector3 localShakeOffset = Vector3.zero;
|
||||
private Transform mainCamera;
|
||||
private bool isShaking = false;
|
||||
private Vector3 lastShakeOffset = Vector3.zero;
|
||||
|
||||
void Start()
|
||||
{
|
||||
enabled = false;
|
||||
mainCamera = Camera.main?.transform; // Pobranie MainCamera
|
||||
if (mainCamera == null)
|
||||
{
|
||||
Debug.LogError("CameraShaker: MainCamera not found!");
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = true; // Skrypt mo¿e byæ w³¹czony, ale shake dzia³a tylko po evencie
|
||||
}
|
||||
|
||||
public void StartShake()
|
||||
{
|
||||
enabled = true;
|
||||
m_position = transform.localPosition;
|
||||
if (isShaking) return; // Jeœli shake ju¿ dzia³a, nie uruchamiaj ponownie
|
||||
|
||||
isShaking = true;
|
||||
shakeTime = 0f;
|
||||
lastShakeOffset = Vector3.zero; // Reset poprzedniego przesuniêcia
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate()
|
||||
{
|
||||
transform.localPosition += new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
|
||||
if (isShaking && shakeTime < duration)
|
||||
{
|
||||
shakeTime += Time.deltaTime;
|
||||
float shakeStrength = amplitude * shakeCurve.Evaluate(shakeTime / duration);
|
||||
|
||||
// P³ynne drgania na bazie Perlin Noise
|
||||
float x = (Mathf.PerlinNoise(Time.time * frequency, 0) * 2 - 1) * shakeStrength;
|
||||
float y = (Mathf.PerlinNoise(0, Time.time * frequency) * 2 - 1) * shakeStrength;
|
||||
float z = (Mathf.PerlinNoise(Time.time * frequency, Time.time * frequency) * 2 - 1) * shakeStrength;
|
||||
|
||||
// Nowe przesuniêcie
|
||||
localShakeOffset = new Vector3(x, y, z);
|
||||
|
||||
// Usuwamy poprzednie przesuniêcie, dodajemy nowe
|
||||
mainCamera.localPosition -= lastShakeOffset;
|
||||
mainCamera.localPosition += localShakeOffset;
|
||||
|
||||
// Zapamiêtujemy ostatnie przesuniêcie
|
||||
lastShakeOffset = localShakeOffset;
|
||||
}
|
||||
else if (shakeTime >= duration)
|
||||
{
|
||||
isShaking = false;
|
||||
mainCamera.localPosition -= lastShakeOffset; // Resetujemy shake
|
||||
lastShakeOffset = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user