using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraShake : MonoBehaviour
{
public float ShakeTimer = 1.0f;
public float ShakeAmount = 1.0f;
private bool isShaking;
private Vector3 startPosition;
private float currentShakeTimer;
}
// Use this for initialization
void Start()
{
startPosition = transform.position;
isShaking = false;
}
// Update is called once per frame
void Update()
{
if (other.tag == "Player")
{
ShakeCamera();
}
if (currentShakeTimer > 0)
{
var shakePos = Random.insideUnitCircle * ShakeAmount;
transform.position = new Vector3(startPosition.x + shakePos.x, startPosition.y + shakePos.y, startPosition.z);
currentShakeTimer -= Time.deltaTime;
}
else if(isShaking)
{
if (transform.position != startPosition)
{
transform.position = startPosition;
}
isShaking = false;
}
}
public void ShakeCamera()
{
isShaking = true;
currentShakeTimer = ShakeTimer;
}