Unity3D相机震动效果
生活随笔
收集整理的這篇文章主要介紹了
Unity3D相机震动效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在一些格斗、射擊以及動作類游戲中
相機震動效果是十分重要的
一個平凡的鏡頭
在關鍵時刻加入相機震動后
便可以展現出碰撞、危險、打斗以及激動人心的效果
相機震動的實現方式有很多
但都會涉及攝像機位置的變化
using System.Collections;
using UnityEngine;
public class CameraShake : MonoBehaviour {
private Transform ThisTransform = null;
public float ShakeTime = 2.0f;
public float ShakeAmount = 3.0f;
public float ShakeSpeed = 2.0f;
// Use this for initialization
void Start () {
ThisTransform = GetComponent<Transform>();
}
public IEnumerator Shake() {
Vector3 OrigPosition = ThisTransform.localPosition;
float ElapsedTime = 0.0f;
while (ElapsedTime < ShakeTime) {
Vector3 RandomPoint = OrigPosition + Random.insideUnitSphere * ShakeAmount;
ThisTransform.localPosition = Vector3.Lerp(ThisTransform.localPosition,RandomPoint,Time.deltaTime*ShakeSpeed);
yield return null;
ElapsedTime += Time.deltaTime;
}
ThisTransform.localPosition = OrigPosition;
}
}
使用時
將此腳本掛到相機上
然后在需要的時候開啟協程即可
StartCoroutine(Shake());
總結
以上是生活随笔為你收集整理的Unity3D相机震动效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS真机调试之免费预配(Free pr
- 下一篇: Opencv+C++之身份证识别(一)