下記コードにて、
アニメーションコンポーネントは親に付いているのでまず親を取得しコンポーネントを指定します。
ですが削除でエラーが起きてしまいます。
よろしくお願いします。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health3 : MonoBehaviour
{
public const int maxHealth = 10;
public int currentHealth = maxHealth;
public void TakeDamage(int amount) { currentHealth -= amount; if (currentHealth <= 0) { //コンポーネントを取得 gameObject.GetComponentsInParent<Animation> (); // 指定したコンポーネントを削除 Destroy(Component); } }
}
コードは ``` と ``` の間に書くと整形されて読みやすくなりますよ。
回答2件
あなたの回答
tips
プレビュー