Unity笔记(9):Camera Shake【相机抖动】 |
您所在的位置:网站首页 › unity怎么编写代码让特效play › Unity笔记(9):Camera Shake【相机抖动】 |
续接上文的爆炸效果: Unity笔记(8):Use Particle System【粒子系统】_代码骑士的博客-CSDN博客 实现相机抖动效果在相机挂载组件 using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraShake : MonoBehaviour { public IEnumerator Shake(float duration,float magnitude)//摇晃时间、幅度 { Vector3 originalPos = transform.localPosition;//相机原始位置 float elapsed = 0.0f;//摇晃进行时间 while (elapsed < duration) { float x = Random.Range(-2f, 2f) * magnitude;//x轴随机抖动幅度 float y = Random.Range(-2f, 2f) * magnitude;//y轴随机抖动幅度 transform.localPosition = new Vector3(x, y, originalPos.z); elapsed += Time.deltaTime; yield return null; } transform.localPosition = originalPos;//再次复原 } }在物体上增加代码: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Boom : MonoBehaviour { public float delay = 3f;//爆炸前延时时间 float countdown;//倒计时 bool hasExploded = false;//确认是否爆炸 public GameObject explosionEffect; public CameraShake cameraShake; void Start() { countdown = delay; } // Update is called once per frame void Update() { countdown -= Time.deltaTime; if (countdown |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |