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"); } } } |
執行,能夠看到默認角色是休閑狀態,點擊button是攻擊狀態。例如以下圖所看到的:
查看模型,能夠看到武器是綁在右手上的,例如以下圖所看到的:
給
武器(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"); } } } |
將
Trail對象賦給
My Trail屬性,例如以下圖所看到的:
如今執行,能夠看到休閑狀態時。武器拖尾的若隱若現,例如以下圖所看到的:
攻擊時的效果:
要調整好 Trail對象的位置、旋轉等,盡量貼合武器,設置拖尾的高度,盡量與武器同長度。才干產生較好的效果。

如今執行,能夠看到休閑狀態時。武器拖尾的若隱若現,例如以下圖所看到的:

攻擊時的效果:

要調整好 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(); } |

武器回收的時候,也不會有拖尾了。例如以下圖所看到的:

參考資料:
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