lucid-super-dream/Assets/TunnelController.cs

40 lines
1.0 KiB
C#
Raw Normal View History

2021-01-09 19:18:55 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
using Ktyl.Util;
using UnityEngine;
2021-01-10 06:55:45 +01:00
public class TunnelController : MonoBehaviour
2021-01-09 19:18:55 +01:00
{
[SerializeField] private SerialFloat _intensity;
[SerializeField] private SerialFloat _duration;
[SerializeField] private AnimationCurve _anim;
2021-01-10 06:55:45 +01:00
[SerializeField] private SerialFloat _playerXPos;
[SerializeField] private SerialFloat _playerXMove;
2021-01-09 19:18:55 +01:00
private float _start = -1;
private void Awake()
{
Shader.SetGlobalFloat("_CameraShake", 0);
}
void LateUpdate()
{
2021-01-10 06:55:45 +01:00
Shader.SetGlobalFloat("_PlayerXMove", _playerXMove);
Shader.SetGlobalFloat("_PlayerXPos", _playerXPos);
2021-01-09 19:18:55 +01:00
var elapsed = Time.time - _start;
if (elapsed > _duration) return;
var normalisedElapsed = elapsed / _duration;
2021-01-10 06:55:45 +01:00
2021-01-09 19:18:55 +01:00
Shader.SetGlobalFloat("_CameraShake", _anim.Evaluate(normalisedElapsed) * _intensity);
}
2021-01-10 06:55:45 +01:00
public void LoseLifeShake()
2021-01-09 19:18:55 +01:00
{
_start = Time.time;
}
}