M4枪 射击特效

Gun.js源码

    function GenerateGraphicStuff(hit : RaycastHit)
{
var hitType : HitType; var body : Rigidbody = hit.collider.rigidbody;
if(body == null)
{
if(hit.collider.transform.parent != null)
{
body = hit.collider.transform.parent.rigidbody;
}
} if(body != null)
{
if(body.gameObject.layer != 10 && !body.gameObject.name.ToLower().Contains("door"))
{
body.isKinematic = false;
} if(!body.isKinematic)
{
var direction : Vector3 = hit.collider.transform.position - weaponTransformReference.position;
body.AddForceAtPosition(direction.normalized * pushPower, hit.point, ForceMode.Impulse);
}
} var go : GameObject; var delta : float = -0.02;
var hitUpDir : Vector3 = hit.normal;
var hitPoint : Vector3 = hit.point + hit.normal * delta; switch(hit.collider.tag)
{
case "wood":
hitType = HitType.WOOD;
go = GameObject.Instantiate(woodParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "metal":
hitType = HitType.METAL;
go = GameObject.Instantiate(metalParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "car":
hitType = HitType.METAL;
go = GameObject.Instantiate(metalParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "concrete":
hitType = HitType.CONCRETE;
go = GameObject.Instantiate(concreteParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "dirt":
hitType = HitType.CONCRETE;
go = GameObject.Instantiate(sandParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "sand":
hitType = HitType.CONCRETE;
go = GameObject.Instantiate(sandParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
case "water":
go = GameObject.Instantiate(waterParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
break;
default:
return;
} go.layer = hit.collider.gameObject.layer; if(hit.collider.renderer == null) return; if(timerToCreateDecal < 0.0 && hit.collider.tag != "water")
{
go = GameObject.Instantiate(bulletMark, hit.point, Quaternion.FromToRotation(Vector3.forward, -hit.normal));
var bm : BulletMarks = go.GetComponent("BulletMarks");
bm.GenerateDecal(hitType, hit.collider.gameObject);
timerToCreateDecal = 0.02;
}
}

分析

根据枪射击到不同的材质,实例化不同的特效

子弹打到的痕迹

子弹打在材质上表面留下的痕迹:贴花系统,没怎么看明白,Decal System

文档资料

http://game.ceeger.com/Components/shader-NormalDecal.html

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-textureCoord.html

BulletMarks.js 重点代码

#pragma strict
#pragma implicit
#pragma downcast enum HitType
{
CONCRETE,
WOOD,
METAL,
OLD_METAL,
GLASS,
GENERIC
} class BulletMarks extends MonoBehaviour
{
public var concrete : Texture2D[];
public var wood : Texture2D[];
public var metal : Texture2D[];
public var oldMetal : Texture2D[];
public var glass : Texture2D[];
public var generic : Texture2D[]; public function GenerateDecal(type : HitType, go : GameObject)
{
var useTexture : Texture2D;
var random : int;
switch(type)
{
case HitType.GENERIC:
if(generic == null) return;
if(generic.Length == 0) return; random = Random.Range(0, generic.Length); useTexture = generic[random];
break;
.......
default:
if(wood == null) return;
if(wood.Length == 0) return; random = Random.Range(0, wood.Length); useTexture = wood[random];
return;
} transform.Rotate(new Vector3(0, 0, Random.Range(-180.0, 180.0))); Decal.dCount++;
var d : Decal = gameObject.GetComponent("Decal");
d.affectedObjects = new GameObject[1];
d.affectedObjects[0] = go;
d.decalMode = DecalMode.MESH_COLLIDER;
d.pushDistance = 0.009 + BulletMarkManager.Add(gameObject);
var m : Material = new Material(d.decalMaterial);
m.mainTexture = useTexture;
d.decalMaterial = m;
d.CalculateDecal();
d.transform.parent = go.transform;
}

贴图

Unity Sample Bootcamp的更多相关文章

  1. 台北Unity开发者研讨会 笔记

    本文转自:http://ndark.wordpress.com/2013/05/12/20130511-台北unity开发者研讨会-笔记/ (墙外) 说明 本文单纯只是笔记,若有笔误敬请见谅. 相关参 ...

  2. Re:Unity游戏开发有哪些让你拍案叫绝的技巧?

    这是我在知乎一个问题: <Unity游戏开发有哪些让你拍案叫绝的技巧?> 下面的回答,觉得蛮有趣的,贴在这里和博客的朋友们分享下. ----- 分享一个比较好玩的内容吧. 大家都知道Uni ...

  3. (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10)

    (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10) 系统要求 64位 Windows 10 除了家庭版的 都支持 ~ 64位CPU CPU至少是四核心以上~ 至少 ...

  4. unity, 立即生效动画:Animation.sample()

    在调用了动画播放之后,动画并不会立即应用(骨骼Transform并不会立即改变),最快也要等到本帧lateUpdate才能生效. 如果有特殊需求,希望在调用了动画播放之后立即生效,则可以紧接着调一句A ...

  5. unity 拿shadowmap/ sample shadow map/拿_ShadowMapTexture

    https://gamedev.stackexchange.com/questions/96051/unity-5-how-to-get-a-shadowmap UNITY_DECLARE_SHADO ...

  6. unity vr sample on htc vive

    http://forum.unity3d.com/threads/unity-vr-samples-now-available.372753/

  7. unity free asset

    Unity Test Tools https://www.assetstore.unity3d.com/#/content/13802 Sample Assets (beta) https://www ...

  8. Unity AssetBundle爬坑手记

    这篇文章从AssetBundle的打包,使用,管理以及内存占用各个方面进行了比较全面的分析,对AssetBundle使用过程中的一些坑进行填补指引以及喷!   AssetBundle是Unity推荐的 ...

  9. Unity: Passing Constructor Parameters to Resolve

    In this tutorial we will go through of couple different ways of using custom constructor parameters ...

随机推荐

  1. jquery实现拖拽以及jquery监听事件的写法

    很久之前写了一个jquery3D楼盘在线选择,这么一个插件,插件很简单,因为后期项目中没有实际用到,因此,有些地方不是很完善,后面也懒得再进行修改维护了.最近放到github上面,但是也少有人问津及s ...

  2. arcgis python 更新顺序号

    i = 0def myFun(): global i i=i +1 return i myFun() ========================== accumulate(  ) total = ...

  3. oracle断电重启之ORA-00600[4194]

    1.问题描述 Oracle服务器断电重启以后无法数据库无法正常连接,使用sqlplus envision/envision连接报错.常见的错误有以下这些: ORA-12518: TNS:listene ...

  4. Android 购物车功能的实现

    首先,众所周知,ListView是Android最常用的控件,可以说是最简单的控件,也可以说是最复杂的控件. 作为一个Android初级开发者,可能会简单的ListView展示图文信息. 作为一个有一 ...

  5. 二叉查找树(binary search tree)详解

    二叉查找树(Binary Search Tree),也称二叉排序树(binary sorted tree),是指一棵空树或者具有下列性质的二叉树: 若任意节点的左子树不空,则左子树上所有结点的值均小于 ...

  6. iOS提醒用户进入设置界面进行重新授权通知定位等功能

    iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置.通知.联系人.相机.日历以及健康等设置. 大多数应用程序仅仅是弹出一个包含操作指令的警示窗口,如“ ...

  7. 在virtualbox下使用vm映像文件

    virtualbox可以直接打开vmdk 创建虚拟机时先不要创建虚拟硬盘. 虚拟机创建成功后,在设置窗口,点击[存储],添加虚拟硬盘,点击选择现有的虚拟盘. 参考链接

  8. struts2.3.24 + spring4.1.6 + hibernate4.3.11+ mysql5.5.25开发环境搭建及相关说明

    一.目标 1.搭建传统的ssh开发环境,并成功运行(插入.查询) 2.了解c3p0连接池相关配置 3.了解验证hibernate的二级缓存,并验证 4.了解spring事物配置,并验证 5.了解spr ...

  9. JavaScript Patterns 4.6 Immediate Object Initialization

    ( { // here you can define setting values // a.k.a. configuration constants maxwidth : 600, maxheigh ...

  10. Spring依赖注入三种方式详解

    在讲解Spring依赖注入之前的准备工作: 下载包含Spring的工具jar包的压缩包 解压缩下载下来的Spring压缩包文件 解压缩之后我们会看到libs文件夹下有许多jar包,而我们只需要其中的c ...