質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

779閲覧

敵に当たったときのアニメーションが終わった後にSet as Layer Default Stateに設定されたアニメーションを開始させたい

hosituka

総合スコア15

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2021/01/02 13:24

敵に当たったときのアニメーションの動きはできたのですが(当たった時の処理はコードの下にあります
そのアニメーションが終わったあとSet as Layer Default Stateに設定されたアニメーションに戻るのが実力不足で出来ません

アニメーションを切り替えるときに使っている変数はBool型ですその変数がtureになった時に敵に当たったときのアニメーションが開始されますSet as Layer Default Stateに設定されたアニメーションの場合はfalseで切り替わります

一応敵に当たったときのアニメーションが終わるまでCoroutineまたはInvokeで命令を停止させて
その後にfalseにしてSet as Layer Default Stateに設定されたアニメーションを動かそうと思いましたが
それが知識不足で出来ませんでしたのでこんな投げやりな質問をしましたすみません
開発環境表記

プラットフォームはWebGL
バージョンは2020,1.14f1

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class HP : MonoBehaviour 7{ 8 private Animator anim = null; 9 public GameObject hp_object = null; 10 public int hp_num = 0; 11 float anim_time; 12 13 // Start is called before the first frame update 14 void Start() 15 { 16 anim = GetComponent<Animator>(); 17 18 } 19 20 // Update is called once per frame 21 void Update() 22 { 23 Text hp_text = hp_object.GetComponent<Text>(); 24 25 hp_text.text = "HP" + hp_num; 26 if (hp_num < 1) 27 { 28 Shooting component = this.gameObject.GetComponent<Shooting>(); 29 Destroy(component); 30 Debug.Log("しにました"); 31 anim.SetBool("bakuhatu", true); 32 33 Destroy(this.gameObject, 1f); 34 } 35 } 36 void OnTriggerEnter2D(Collider2D collision) 37 { 38 39 hp_num -= 1 ; 40 //敵に当たったときのアニメーションが開始される 41 anim.SetBool("hidame", true); 42 43 //ここで0.1秒だけとめたい(アニメーションが終わるのがちょうど0.1秒)  44 45 //Set as Layer Default Stateに設定されたアニメーションが開始される 46     anim.SetBool("hidame", false); 47 } 48 49} 50

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

前述したコードInvokeを使用してこう書きたしたら出来ました
自分の思った通りに動くとプログラミング楽しいですね

c#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class HP : MonoBehaviour 7{ 8 private Animator anim = null; 9 public GameObject hp_object = null; 10 public int hp_num = 0; 11 float anim_time; 12 13 // Start is called before the first frame update 14 void Start() 15 { 16 anim = GetComponent<Animator>(); 17 18 } 19 20 // Update is called once per frame 21 void Update() 22 { 23 Text hp_text = hp_object.GetComponent<Text>(); 24 25 hp_text.text = "HP" + hp_num; 26 if (hp_num < 1) 27 { 28 Shooting component = this.gameObject.GetComponent<Shooting>(); 29 Destroy(component); 30 Debug.Log("しにました"); 31 anim.SetBool("bakuhatu", true); 32 33 Destroy(this.gameObject, 1f); 34 } 35 } 36 void OnTriggerEnter2D(Collider2D collision) 37 { 38 hp_num -= 1 ; 39 anim.SetBool("hidame", true); 40 Invoke("oniku", 1f); 41 42 } 43 void oniku() 44 { 45 Debug.Log("unnti"); 46 anim.SetBool("hidame", false); 47 } 48} 49

投稿2021/01/03 05:29

編集2021/01/03 05:31
hosituka

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問