查看: 468|回复: 0
打印 上一主题 下一主题

[其他] 震屏效果的代码

[复制链接]
may    

8830

主题

80

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52304
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2016-1-30 23:06:44 |只看该作者 |倒序浏览
  1. using UnityEngine;
  2. using System.Collections;
  3. publicclass ScreenShake : MonoBehaviour
  4. {
  5.     privatefloat shakeTime = 0.0f;
  6.     privatefloat fps= 20.0f;
  7.     privatefloat frameTime =0.0f;
  8.     privatefloat shakeDelta =0.005f;
  9.     public  Camera cam ;
  10.     publicstaticbool isshakeCamera =false;
  11.     // Use this for initializationvoid Start ()
  12.     {
  13.         shakeTime = 2.0f;
  14.         fps= 20.0f;
  15.         frameTime =0.03f;
  16.         shakeDelta =0.005f;
  17.    //isshakeCamera=true;
  18.     }
  19.    
  20.     // Update is called once per framevoid Update ()
  21.     {
  22.         if (isshakeCamera)
  23.         {
  24.             if(shakeTime > 0)
  25.             {
  26.                 shakeTime -= Time.deltaTime;
  27.                 if(shakeTime <= 0)
  28.                 {
  29.                     cam.rect = new Rect(0.0f,0.0f,1.0f,1.0f);
  30.                     isshakeCamera =false;
  31.                     shakeTime = 1.0f;
  32.                     fps= 20.0f;
  33.                     frameTime =0.03f;
  34.                     shakeDelta =0.005f;
  35.                 }
  36.                 else
  37.                 {
  38.                     frameTime += Time.deltaTime;
  39.                     
  40.                     if(frameTime > 1.0 / fps)
  41.                     {
  42.                         frameTime = 0;
  43.                         cam.rect = new Rect(shakeDelta * ( -1.0f + 2.0f * Random.value),shakeDelta * ( -1.0f + 2.0f * Random.value), 1.0f, 1.0f);
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-10 08:29 , Processed in 0.080426 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部