Unity3D中抖屏(抖動相機)效果的簡單實現


這里是一個簡單的攝像機抖動方法,記錄下來便於查閱。

public class CameraShake : MonoBehaviour {

    // 抖動目標的transform(若未添加引用,怎默認為當前物體的transform)
    public Transform camTransform;

    //持續抖動的時長
    public float shake = 0f;

    // 抖動幅度(振幅)
  //振幅越大抖動越厲害
public float shakeAmount = 0.7f; public float decreaseFactor = 1.0f; Vector3 originalPos; void Awake() { if (camTransform == null) { camTransform = GetComponent(typeof(Transform)) as Transform; } } void OnEnable() { originalPos = camTransform.localPosition; } void Update() { if (shake > 0) { camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount; shake -= Time.deltaTime * decreaseFactor; } else { shake = 0f; camTransform.localPosition = originalPos; } } }

實際上可以抖動任何物體。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM