Super Knight : Enter the Dungeon
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
|
|
|
|
public class TiltCamera : MonoBehaviour {
|
|
|
|
|
[OnlyRead]
|
|
|
|
|
public bool isShaking = false;
|
|
|
|
|
[Range(0, 2f)]
|
|
|
|
|
public float shakePower = 0.02f;
|
|
|
|
|
[Range(0, 1f)]
|
|
|
|
|
public float time = 0.2f;
|
|
|
|
|
private Vector3 initialPosition;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
initialPosition = transform.localPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float timeSum = 0;
|
|
|
|
|
public void Shaking(float power, float duration)
|
|
|
|
|
{
|
|
|
|
|
if (0 < power)
|
|
|
|
|
{
|
|
|
|
|
shakePower = power;
|
|
|
|
|
time = duration;
|
|
|
|
|
|
|
|
|
|
if (!isShaking)
|
|
|
|
|
StartCoroutine(ShakingCo());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IEnumerator ShakingCo()
|
|
|
|
|
{
|
|
|
|
|
isShaking = true;
|
|
|
|
|
Vector3 pos = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
timeSum = 0;
|
|
|
|
|
while (timeSum < time)
|
|
|
|
|
{
|
|
|
|
|
yield return null;
|
|
|
|
|
|
|
|
|
|
if (isShaking)
|
|
|
|
|
{
|
|
|
|
|
pos = initialPosition + Random.insideUnitSphere * shakePower;
|
|
|
|
|
pos.z = initialPosition.z;
|
|
|
|
|
transform.localPosition = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeSum += Time.deltaTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transform.localPosition = initialPosition;
|
|
|
|
|
isShaking = false;
|
|
|
|
|
}
|
|
|
|
|
}
|