参考書をそのままうつしたものなのですがcollider.enabled = true;の部分で
error CS0266: Cannot implicitly convert type UnityEngine.Component' to
UnityEngine.Collider'. An explicit conversion exists (are you missing a cast?)とエラーが出てしまいました。
明示的にキャストしろみたいなことだと思うのですがどのようにキャストすればよいのでしょうか?
よろしくお願いします。
using UnityEngine; using System.Collections; public class AttackArea : MonoBehaviour { CharacterStatus status; void Start() { status = transform.root.GetComponent<CharacterStatus>(); } public class AttackInfo { public int attackPower; // この攻撃の攻撃力. public Transform attacker; // 攻撃者. } // 攻撃情報を取得する. AttackInfo GetAttackInfo() { AttackInfo attackInfo = new AttackInfo(); // 攻撃力の計算. attackInfo.attackPower = status.Power; attackInfo.attacker = transform.root; return attackInfo; } // 当たった. void OnTriggerEnter(Collider other) { // 攻撃が当たった相手のDamageメッセージをおくる. other.SendMessage("Damage",GetAttackInfo()); // 攻撃した対象を保存. status.lastAttackTarget = other.transform.root.gameObject; } // 攻撃判定を有効にする. void OnAttack() { collider.enabled = true; } // 攻撃判定を無効にする. void OnAttackTermination() { collider.enabled = false; } }
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/16 10:11