以下のコードだとエラーで動きません。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Health5 : MonoBehaviour { public int Health = 10; public int MaximumHealth = 10; private void OnCollisionEnter(Collision collision) { this.Damage(1); } public void Damage(int value) { this.Health = Mathf.Clamp(this.Health - value, 0, this.MaximumHealth); // ダメージ表現 var ratio = (float)this.Health / this.MaximumHealth; this.GetComponent<Renderer>().material.color = new Color(1.0f, ratio, ratio); if (this.Health > 0) { return; } var FixedJoint = this.GetComponent<FixedJoint>(); if (FixedJoint == null) { return; } FixedJoint.enabled = false; } }
以下のコードだとエラーは無いのですが、パージされません。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Health1 : MonoBehaviour { public const int maxHealth = 10; public int currentHealth = maxHealth; public void TakeDamage(int amount) { currentHealth -= amount; if (currentHealth <= 0) { //コンポーネントを取得 FixedJoint component = this.gameObject.GetComponent<FixedJoint>(); // 指定したコンポーネントを削除 Destroy(component); } } }
どのような問題があるのか教えて下さい。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/06 15:40
2019/01/06 15:51
2019/01/07 16:37
2019/01/07 19:54
2019/01/08 19:08
2019/01/08 21:13 編集
2019/01/10 16:36
2019/01/10 22:56 編集
2019/01/13 16:18