unity震动效果
2024-10-18 23:31:36
using System.Collections;
using System.Collections.Generic;
using UnityEngine; //思想:在短时间内在规定圆内随机震动对象位置,从而实现震动效果
public class CamZhengDong : MonoBehaviour {
//震动对象属性
private Transform Tr = null;
//
public float zhenDongShiJian = 6.0f;
//震动幅度
public float fuDu = 10.0f;
//震动对象移动速度
public float speed = 2.0f; // Use this for initialization
void Start () {
Tr = GetComponent<Transform>();
StartCoroutine(CamShake());
} //private void Update()
//{
// if (ElapsedTime < ShakeTime) {
// Vector3 RanPoint = OrigPosition + Random.insideUnitSphere * ShakeAmount;
// Tr.localPosition = Vector3.Lerp(Tr.localPosition, RanPoint, Time.deltaTime * speed);
// //计时
// ElapsedTime += Time.deltaTime;
// }
//} public IEnumerator CamShake() {
float jishi = 0.0f;
Vector3 OrigPosition = Tr.localPosition;
while (jishi < zhenDongShiJian) {
//Random.insideUnitSphere单位圆内随机数
Vector3 RanPoint = OrigPosition + Random.insideUnitSphere * zhenDongShiJian;
Tr.localPosition = Vector3.Lerp(Tr.localPosition,RanPoint,Time.deltaTime * speed);
yield return null;
//计时
jishi += Time.deltaTime;
}
} }
最新文章
- javascript遍历算法与技巧
- python 之禅
- cuda编程基础
- ASP.NET 5探险(1):Azure中配置连接字符串、独立项目执行EF7数据迁移
- 三、Authentication &; sessionid
- ZOJ 3811
- uva 10474 Where is the Marble? 计数排序
- Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca
- UI进阶 动画
- 学习笔记6_Java_day11_JSP_基础和入门(1、2)
- [转] 条件变量(Condition Variable)详解
- web编程速度大比拼(nodejs go python)(非专业对比)
- 安装IntelliJ IDEA JetGroovy(转)
- angularjs的directive详解
- 爬虫:把廖雪峰的教程转换成 PDF 电子书
- 恶补web之一:html学习(2)
- 【搬运工】redis 启动和关闭
- 2018-11-13 中文代码示例之Programming in Scala学习笔记第二三章
- LeetCode算法题-Linked List Cycle(Java实现)
- ASP.NET Core中使用Unity5