Unity 武器拖尾效果
来源:互联网 发布:淘宝女装代销 编辑:程序博客网 时间:2024/04/27 13:21
Pocket RPG Weapon Trails 武器拖尾效果
Asset Store地址:https://www.assetstore.unity3d.com/en/#!/content/2458
CSDN资源地址:http://download.csdn.net/detail/akof1314/7610241
CSDN资源地址:http://download.csdn.net/detail/akof1314/7610241
截图:
由于这个插件提供的AnimationController.cs仅对Animation动画进行支持,对Animator动画支持的话需要自己实现。文档上说明实现的方式:
由于这个插件提供的AnimationController.cs仅对Animation动画进行支持,对Animator动画支持的话需要自己实现。文档上说明实现的方式:
- The WeaponTrail can be built by calling Itterate(float itterateTime) and UpdateTrail(float currentTime, float deltaTime). These functions are called by AnimationController, however if you don't want to use AnimationController you can call these yourself.
即只需要调用Itterate和UpdateTrail方法。下面使用另外的角色模型进行测试拖尾效果。
CSDN资源地址:http://download.csdn.net/detail/akof1314/7610385
首先,在Animator窗口,创建休闲idle状态和攻击attack状态,设置它们相应的Motion,设置从idle到attack的动画参数为Attack,类型为Trigger,如下图所示:
Speed属性可以控制当前状态动作的速度。接着,创建个脚本TestMyTrail.cs附加到角色上,脚本代码如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using UnityEngine;
using System.Collections;
public class TestMyTrail : MonoBehaviour {
private Animator animator;
void Start () {
animator = GetComponent<Animator>();
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "攻击"))
{
animator.SetTrigger("Attack");
}
}
}
using System.Collections;
public class TestMyTrail : MonoBehaviour {
private Animator animator;
void Start () {
animator = GetComponent<Animator>();
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "攻击"))
{
animator.SetTrigger("Attack");
}
}
}
运行,可以看到默认角色是休闲状态,点击按钮是攻击状态,如下图所示:
查看模型,可以看到武器是绑在右手上的,如下图所示:
给武器(Object003)添加一个子对象,命名为Trail,为其添加WeaponTrail.cs脚本、Mesh Renderer组件,材质为Pocket RPG Trails提供的材质,设置好如下图所示:查看模型,可以看到武器是绑在右手上的,如下图所示:
修改TestMyTrail.cs代码为如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEngine;
using System.Collections;
public class TestMyTrail : MonoBehaviour {
public WeaponTrail myTrail;
private Animator animator;
private float t = 0.033f;
private float tempT = 0;
private float animationIncrement = 0.003f;
void Start ()
{
animator = GetComponent<Animator>();
}
void LateUpdate()
{
t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);
if (t > 0)
{
while (tempT < t)
{
tempT += animationIncrement;
if (myTrail.time > 0)
{
myTrail.Itterate(Time.time - t + tempT);
}
else
{
myTrail.ClearTrail();
}
}
tempT -= t;
if (myTrail.time > 0)
{
myTrail.UpdateTrail(Time.time, t);
}
}
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "攻击"))
{
animator.SetTrigger("Attack");
}
}
}
using System.Collections;
public class TestMyTrail : MonoBehaviour {
public WeaponTrail myTrail;
private Animator animator;
private float t = 0.033f;
private float tempT = 0;
private float animationIncrement = 0.003f;
void Start ()
{
animator = GetComponent<Animator>();
}
void LateUpdate()
{
t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);
if (t > 0)
{
while (tempT < t)
{
tempT += animationIncrement;
if (myTrail.time > 0)
{
myTrail.Itterate(Time.time - t + tempT);
}
else
{
myTrail.ClearTrail();
}
}
tempT -= t;
if (myTrail.time > 0)
{
myTrail.UpdateTrail(Time.time, t);
}
}
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "攻击"))
{
animator.SetTrigger("Attack");
}
}
}
将Trail对象赋给My Trail属性,如下图所示:
现在运行,可以看到休闲状态时,武器拖尾的若隐若现,如下图所示:
攻击时的效果:
要调整好Trail对象的位置、旋转等,尽量贴合武器,设置拖尾的高度,尽量与武器同长度,才能产生较好的效果。当攻击结束,武器往回收的时候,也会有拖尾,如下图所示:
如果要去掉这个时候的拖尾,可以采用更精确的控制拖尾的出现。选中攻击动作,切换到"Animations",播放动作,在攻击开始时刻,添加一个事件,如下图所示:
在攻击完毕,也添加一个事件,如下图所示:
现在运行,可以看到休闲状态时,武器拖尾的若隐若现,如下图所示:
攻击时的效果:
要调整好Trail对象的位置、旋转等,尽量贴合武器,设置拖尾的高度,尽量与武器同长度,才能产生较好的效果。当攻击结束,武器往回收的时候,也会有拖尾,如下图所示:
如果要去掉这个时候的拖尾,可以采用更精确的控制拖尾的出现。选中攻击动作,切换到"Animations",播放动作,在攻击开始时刻,添加一个事件,如下图所示:
在攻击完毕,也添加一个事件,如下图所示:
点击"Apply"进行应用。修改TestMyTrail.cs代码为如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void Start ()
{
animator = GetComponent<Animator>();
// 默认没有拖尾效果
myTrail.SetTime(0.0f, 0.0f, 1.0f);
}
public void heroAttack()
{
//设置拖尾时长
myTrail.SetTime(2.0f, 0.0f, 1.0f);
//开始进行拖尾
myTrail.StartTrail(0.5f, 0.4f);
}
public void heroIdle()
{
//清除拖尾
myTrail.ClearTrail();
}
{
animator = GetComponent<Animator>();
// 默认没有拖尾效果
myTrail.SetTime(0.0f, 0.0f, 1.0f);
}
public void heroAttack()
{
//设置拖尾时长
myTrail.SetTime(2.0f, 0.0f, 1.0f);
//开始进行拖尾
myTrail.StartTrail(0.5f, 0.4f);
}
public void heroIdle()
{
//清除拖尾
myTrail.ClearTrail();
}
武器回收的时候,也不会有拖尾了,如下图所示:
参考资料:
1.Unity3D 武器拖尾效果(刀光) 使用PocketRPG Trails http://blog.csdn.net/xv_ly15/article/details/8509781
2.Unity3D研究院之挥动武器产生的剑痕特效(四十七) http://www.xuanyusong.com/archives/2110
1.Unity3D 武器拖尾效果(刀光) 使用PocketRPG Trails http://blog.csdn.net/xv_ly15/article/details/8509781
2.Unity3D研究院之挥动武器产生的剑痕特效(四十七) http://www.xuanyusong.com/archives/2110
4 0
- Unity 武器拖尾效果
- Unity 武器拖尾效果
- Unity 武器拖尾效果
- unity 武器拖尾效果实现的代码
- Unity 武器拖尾效果插件Pocket RPG Weapon Trails
- U3D武器拖尾效果
- Unity 武器的刀光剑影效果
- Unity Asset(1)Pocket RPG Weapon Trails 武器拖尾效果
- 插件(一)武器拖尾效果
- Unity(二)武器刀光的效果
- cocos2dx 关于拖影(类似dnf传承武器的拖尾效果)的快速实现
- Unity3D 武器拖尾效果(刀光) 使用PocketRPG Trails
- Unity拖影效果
- Unity拖影效果
- 武器拖尾的实现
- unity创建拖拽的圆周运动效果
- 武器
- POCKET RPG WEAPON TRAILS(for Unity3D)武器拖尾插件
- [DELPHI-码农]理解 Delphi 的类(十) - 深入方法[15] - 调用其他单元的函数
- HDU1010DFS+剪枝
- 色盲色弱测试
- 文化部:制止艺术团赴国外镀金
- ContentResolver.query()的四个参数
- Unity 武器拖尾效果
- rdlc报表在vs2008下编辑正常,在vs2012上编辑就报错
- jqueryui.position.js源码分析
- linux查找文件命令find
- 2014大二下学期期末总结
- 【剑指offer】斐波那契数列
- 最新百度地图—POI搜索功能讲解
- 菜鸟记录,jsp静态与动态引入。
- MATLAB二维、三维布朗运动和球面均匀分布