using UnityEngine; using System.Collections; [RequireComponent( typeof( Light ) )] public class flickeringLight : MonoBehaviour { // Flickering Styles public enum flickerinLightStyles { CampFire = 0, Fluorescent = 1 }; public flickerinLightStyles flickeringLightStyle = flickerinLightStyles.CampFire; // Campfire Methods public enum campfireMethods { Intensity = 0, Range = 1, Both = 2 }; public campfireMethods campfireMethod = campfireMethods.Intensity; // Intensity Styles public enum campfireIntesityStyles { Sine = 0, Random = 1 }; public campfireIntesityStyles campfireIntesityStyle = campfireIntesityStyles.Random; // Range Styles public enum campfireRangeStyles { Sine = 0, Random = 1 }; public campfireRangeStyles campfireRangeStyle = campfireRangeStyles.Random; // Base Intensity Value public float CampfireIntensityBaseValue = 0.5f; // Intensity Flickering Power public float CampfireIntensityFlickerValue = 0.1f; // Base Range Value public float CampfireRangeBaseValue = 10.0f; // Range Flickering Power public float CampfireRangeFlickerValue = 2.0f; // If Style is Sine private float CampfireSineCycleIntensity = 0.0f; private float CampfireSineCycleRange = 0.0f; // "Glow" Speeds public float CampfireSineCycleIntensitySpeed = 5.0f; public float CampfireSineCycleRangeSpeed = 5.0f; public float FluorescentFlickerMin = 0.4f; public float FluorescentFlickerMax = 0.5f; public float FluorescentFlicerPercent = 0.95f; // NOT IMPLEMENTED YET !!!! public bool FluorescentFlickerPlaySound = false; public AudioClip FluorescentFlickerAudioClip; // ------------------------ // Use this for initialization void Start () { } // Update is called once per frame void Update () { switch( flickeringLightStyle ) { // If Flickering Style is Campfire case flickerinLightStyles.CampFire: // If campfire method is Intesity OR Both if( campfireMethod == campfireMethods.Intensity || campfireMethod == campfireMethods.Both ) { // If Intensity style is Sine if( campfireIntesityStyle == campfireIntesityStyles.Sine ) { // Cycle the Campfire angle CampfireSineCycleIntensity += CampfireSineCycleIntensitySpeed; if( CampfireSineCycleIntensity > 360.0f ) CampfireSineCycleIntensity = 0.0f; // Base + Values light.intensity = CampfireIntensityBaseValue + ( ( Mathf.Sin( CampfireSineCycleIntensity * Mathf.Deg2Rad ) * ( CampfireIntensityFlickerValue / 2.0f ) ) + ( CampfireIntensityFlickerValue / 2.0f ) ); } else light.intensity = CampfireIntensityBaseValue + Random.Range( 0.0f, CampfireIntensityFlickerValue ); } // If campfire method is Range OR Both if( campfireMethod == campfireMethods.Range || campfireMethod == campfireMethods.Both ) { // If Range style is Sine if( campfireRangeStyle == campfireRangeStyles.Sine ) { // Cycle the Campfire angle CampfireSineCycleRange += CampfireSineCycleRangeSpeed; if( CampfireSineCycleRange > 360.0f ) CampfireSineCycleRange = 0.0f; // Base + Values light.range = CampfireRangeBaseValue + ( ( Mathf.Sin( CampfireSineCycleRange * Mathf.Deg2Rad ) * ( CampfireSineCycleRange / 2.0f ) ) + ( CampfireSineCycleRange / 2.0f ) ); } else light.range = CampfireRangeBaseValue + Random.Range( 0.0f, CampfireRangeFlickerValue ); } break; // If Flickering Style is Fluorescent case flickerinLightStyles.Fluorescent: if( Random.Range( 0.0f, 1.0f ) > FluorescentFlicerPercent ) { light.intensity = FluorescentFlickerMin; // Check Audio - NOT IMPLEMENTED YET if( FluorescentFlickerPlaySound ) { } } else light.intensity = FluorescentFlickerMax; break; default: // You should not be here. break; } } }
详细解决方案
[转载]Unity3d闪耀灯光脚本
热度:115 发布时间:2012-11-23 00:03:43.0
相关解决方案
- 怎么用 svn 管理 unity3d 项目
- Unity3d Webplayer 障蔽缓存机制
- Unity3D -day03(js、C#互调)
- Unity3d 鼠标捡取 javascript
- unity3d 批改 webplayer 的logo
- unity3d 适用,javaScript 转 C
- Unity3D 学习教程 二 创建游戏工程与界面
- Unity3d SDK篇之Android开发(1)
- Unity3D 学习教程 三 了解工程面板
- unity3d ios开发 调试的流程?该怎么处理
- unity3d ios开发 调试的流程?解决思路
- (转)unity3D iPhone开发有关问题汇总
- Unity3D 搬动平台实现一种大规模(其实跟PC比还是算小规模)动画角色渲染的方案-绝对原创方案。
- Unity3d 播发高质量视频解决方案
- unity3d android开发初体验——远道安装调试篇
- Unity3d 暖更新之Android平台
- Unity3D 怎么在安卓手机上播放视频
- Unity3D C#脚本使用System.Drawing命名空间,发布到Android不能用,安卓程序如何才能使用Bit地图类等
- Unity3d PBR海水点染
- Android Unity3d 腾挪脚本
- 【Unity3D】利用Shader以及改动Mesh实现2D游戏的动态阴影效果
- Unity3D Shader性能排名
- unity3D C#容易代理使用了解
- Delegates, Events and Singletons with Unity3D – C
- Unity3D 双摇杆 c# JoyStick 实现自各儿的双摇杆
- Unity3d-反编译C#跟提取资源
- UNITY3D c#脚本中处置类与结构体的区别
- Unity3D 学习教程 11 c#脚本统制摄像头
- Unity3D 学习教程 十 复制物体
- Unity3D 学习教程 七 基本应用与添加刚体