Unity で特定のアニメーションの再生が終了したかどうかを確認してから、アクションを実行するにはどうすればよいですか? [C#] アニメーターを使用していません。
3 に答える
から: http://answers.unity3d.com/questions/52005/destroy-game-object-after-animation.html
アニメーション エディタからアクションを実行するには...
-オブジェクトを破棄する単純なパブリック関数を使用してスクリプトを作成します。例えば
public class Destroyable : MonoBehaviour
{
public void DestroyMe()
{
Destroy(gameObject);
}
}
-そのスクリプトを、破壊したいアニメーション オブジェクトに追加します。
-アニメーション エディタで、アニメーション スクラバーをアニメーションの最後に移動します。
-アニメーション ツールバーの [イベントの追加] ボタンを使用します。
-[アニメーション イベントの編集] ダイアログの関数ドロップダウンから [DestroyMe] を選択します。
-これで、アニメーションが再生され、「DeleteMe」機能が実行され、オブジェクトが破棄されるか、アクションが実行されます。
私はこの方法を数回使用しましたが、アニメーションの特定のものに役立ちます:)
Animation.IsPlayingの値を確認する必要があります。
ドキュメントから:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Animation anim;
void Start() {
anim = GetComponent<Animation>();
}
void OnMouseEnter() {
if (!anim.IsPlaying("mouseOverEffect"))
anim.Play("mouseOverEffect");
}
}
Andrea が彼の投稿で言ったように: Animation-IsPlayingは、Animator を使用しないので必要なものです。アニメーションをチェックして、使用できる他の甘いものを確認してください。
using UnityEngine;
using UnityEngine.Collections;
public class ExampleClass : MonoBehaviour
{
Animation anim;
void Start()
{
anim = GetComponent<Animation>();
}
//In update or in another method you might want to check
if(!anim.isPlaying("StringWithAnimationClip") //or anim.clip.name
//Do Something
}
anim.Stop(); でアニメーションを強制停止することもできます。
isPlaying() を使用したくないとコメントしたので、詳しく説明していただければ投稿を編集します。