2017-05-09 18 views
0

です以下は私のスクリプトですが、アニメーターの状態が終了したことを確認したいと思います。アニメーターの状態(アニメーション)が完了したら、何らかのアクションを実行しますが、これを有効にしています。ありがとうございます。アニメーターの状態をチェックする方法はunity3d

using UnityEngine; 
using System.Collections; 
public class fun_for_level_complet : MonoBehaviour 
{ 
    public Animator animator_obj; 

    // Use this for initialization 
    void Start() 
    { 

    } 

    // Update is called once per frame 
    void Update() 
    { 
     check_end_state(); 
    } 

    public void level_complete() 
    { 
     if (this.GetComponent<movement_of_player>() != null) 
     { 
      this.GetComponent<movement_of_player>().enabled = false; 
     } 
     animator_obj.SetBool ("congo",true); 

    } 

    public void check_end_state() 
    { 
     // here I want to check if animation ends then print 
     // my state name is congo 
     // animation name Waving 
     // using base layer 
     if (animator_obj.GetCurrentAnimatorStateInfo (0).IsName ("congo") && !animator_obj.IsInTransition (0)) 
     { 
      Debug.Log ("anim_done"); 
     } 
    } 
} 
+0

@RiaanWalters That's Animation。 OPはAnimatorを使用しています。彼らはどちらも異なっています。 – Programmer

+0

@Programmer、十分に公正、私は旗を削除した –

答えて

1

私はそれを理解し、状態が開始するかどうかをチェックすることで終了します。以下のコードで、細かい作業、あなたがアニメーションクリップのイベントを使用することができます(あなたが空の状態を作成する必要が最後の状態で)

using UnityEngine; 
using System.Collections; 

public class fun_for_level_complet : MonoBehaviour 
{ 
public Animator animator_obj; 
private string[] states = new string[]{ "congo" }; 
private string current_state_name = ""; 
private bool waiting_end_state = false; 
private bool wait_for_anim_start = false; 
// Use this for initialization 
void Start() 
{ 

} 

// Update is called once per frame 
void Update() 
{ 
    if (waiting_end_state) 
    { 
     if (wait_for_anim_start) 
     { 
      if (animator_obj.GetCurrentAnimatorStateInfo (0).IsName (current_state_name)) 
      { 

       wait_for_anim_start = false; 
      } 
     } else 
     { 

      check_end_state(); 
     } 
    } 
} 

public void level_complete() 
{ 
    if (this.GetComponent<movement_of_player>() != null) 
    { 
     this.GetComponent<movement_of_player>().enabled = false; 
    } 
    animator_obj.SetBool ("congo",true); 
    waiting_end_state = true; 
    wait_for_anim_start = true; 
    current_state_name = states [0]; 
} 
public void check_end_state() 
{ 

    if (!animator_obj.GetCurrentAnimatorStateInfo (0).IsName (current_state_name)) 
    { 
     waiting_end_state = false; 
     if(current_state_name==states[0]) 
     { 
      GameObject.FindGameObjectWithTag ("inagmegui").SendMessage ("make_it_true"); 
      print ("animation has been ended"); 
     } 
    } 
} 
} 
1

を覚えています。ユニティマニュアルで説明しています: https://docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html

アニメーションのInport設定でAnnimationsタブでは、イベント見出しを見つけることができます。再生を終了位置に置き、イベントを追加するをクリックします。 関数のフィールドに、アニメーションの終了時に呼び出す関数の名前を入力します。このアニメーションのゲームオブジェクトに対応する機能があることを確認してください。

関連する問題