2015年3月16日 星期一

Unity5.0 Animator 建立粒子系統.....

操作方法:  

1. Gameobjcet 新建一個Animation,Unity5.0 會自動建立Animator。
2. Animator視窗進去後,會看到橘色的Animation(設計者建立)。
3. Inspector 視窗底下會看到Add Behaviour 按鈕點下去,會讓設計者尋找腳本。
4. 若沒有腳本選擇New Script後打上Script name 後 點擊Create and add 按鈕建立腳本。
5. 以下程式函式Unity本身就會建立,只是要注意下函式不同的用法即可。

-------------------------------------------------------------------

程式碼部分:

using UnityEngine;
using System.Collections;

public class SpecialAttackParticlesSmb : StateMachineBehaviour {

public GameObject particles;   
public AvatarIKGoal attackLimb; 

private Transform particlesTransform; 
private ParticleSystem particleSystem; 

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {

if(particlesTransform != null)
return;

GameObject particleInstance = Instantiate (particles);
particlesTransform = particleInstance.transform;
particleSystem = particleInstance.GetComponent<ParticleSystem> ();
}

override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
particleSystem.Stop ();
}

override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {

if(particleSystem == null || particlesTransform == null)
return;

Vector3 limnPosistion = animator.GetIKPosition (attackLimb);
Quaternion limbRotation = animator.GetIKRotation (attackLimb);

particlesTransform.position = limnPosistion;
particlesTransform.rotation = limbRotation;

if(!particleSystem.isPlaying)
particleSystem.Play();

}
}

-------------------------------------------------------------------

結果圖:



沒有留言:

張貼留言