まず、Unityの基本的なものが不足しているように見えるので、私のソリューションがうまく動作するようになると思います。
OnTriggerCollisionEnter2D
は、Trigger
を検出する有効なコールバック関数ではありません。
OnTriggerEnter2D(Collider2D coll)
はあなたが探しているものです。
第2に、onTriggerでは何もしないでください。 Start()
関数でアニメーションをロードし、OnTriggerEnter2D
関数で再生します。
if(coll.gameObject.tag = "Player")
は、if(coll.gameObject.tag == "Player")
である必要があります。ダブル '=
'に注目してください。あなたは2倍の '=
'とは比較できません。効率的ではありません。可能であれば、coll.gameObject.tag ==
の代わりにcoll.gameObject.CompareTag
を使用してください。
Assets/Resources/Animation
フォルダ
Animation animation;
AnimationClip animanClip;
string animName = "walk";
// Use this for initialization
void Start()
{
//Load Animation
loadAnimation();
}
void loadAnimation()
{
GameObject tempObj = Resources.Load("Animations/" + animName, typeof(GameObject)) as GameObject;
if (!tempObj == null)
{
Debug.LogError("Animation NOT found");
}
else
{
animation = tempObj.GetComponent<Animation>();
animanClip = animation.clip;
animation.AddClip(animanClip, animName);
}
}
public void OnTriggerEnter2D(Collider2D coll)
{
if (coll.gameObject.CompareTag("Player"))
{
animation.Play(animName);
}
}
にアニメーションを入れて最後に、これらのチュートリアルを勉強。アニメーションが保存されているどのように
Unity Scripting Tutorial
Unity Physics Tutorial
Other Unity Tutorials
? AssetBundleまたは単にプリファブとして?あなたはアセットのスクリーンショットを持っていますか? – Programmer
まず、返信ありがとう:)。アニメーションファイル(.anim)のようなフォルダ/アニメーションフォルダに保存しました –