LoginSignup
6
8

More than 5 years have passed since last update.

.Play でAnimation再実行

Posted at

概要

Animator を使ったアニメーション再実行がうまく動かなかったので
「.Play」 使って無理やり動かした件について

引用元

https://spphire9.wordpress.com/2015/02/13/unity%E3%81%A7%E3%82%A2%E3%83%8B%E3%83%A1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E3%82%82%E3%81%86%E4%B8%80%E5%BA%A6%E5%86%8D%E7%94%9F%E3%81%99%E3%82%8B/

作業

下記のコードをAnimatorコンポーネントが設定してある
オブジェクト内の別スクリプトに記述する。
後は任意の場所で、下記でいう「TestAction()」を呼び出せばOK。

※引数を利用すればアニメーションの開始フレームを指定できる。
 第3引数に 0.0f を設定すれば、何度でも同じアニメーションを頭から再生できる。

コード

test.cs
Animator _anim;

void Start() {
  _anim = GetComponent<Animator>();
}

public void TestAction() {
  _anim.Play("test1", 0, 0.0f);
}

// 第1引数の test1 は AnimatorControllerのstate名
// 第2引数は 指定のレイヤー。 0 =「Base Layer」(多分。)
// 第3引数は アニメーションの開始フレーム。 0.0f = 最初

test1A.png

6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8