C#
1using UnityEngine; 2using System.Collections; 3 4public class AttackArea : MonoBehaviour { 5 CharacterStatus status; 6 7 void Start() 8 { 9 status = transform.root.GetComponent<CharacterStatus>(); 10 } 11 12 13 public class AttackInfo 14 { 15 public int attackPower; // この攻撃の攻撃力. 16 public Transform attacker; // 攻撃者. 17 } 18 19 20 // 攻撃情報を取得する. 21 AttackInfo GetAttackInfo() 22 { 23 AttackInfo attackInfo = new AttackInfo(); 24 // 攻撃力の計算. 25 attackInfo.attackPower = status.Power; 26 // 攻撃強化中 27 if (status.powerBoost) 28 attackInfo.attackPower += attackInfo.attackPower; 29 30 attackInfo.attacker = transform.root; 31 32 return attackInfo; 33 } 34 35 // 当たった. 36 void OnTriggerEnter(Collider other) 37 { 38 // 攻撃が当たった相手のDamageメッセージをおくる. 39 other.SendMessage("Damage",GetAttackInfo()); 40 // 攻撃した対象を保存. 41 status.lastAttackTarget = other.transform.root.gameObject; 42 } 43 44 45 // 攻撃判定を有効にする. 46 void OnAttack() 47 { 48 collider.enabled = true; 49 } 50 51 52 // 攻撃判定を無効にする. 53 void OnAttackTermination() 54 { 55 collider.enabled = false; 56 } 57}
これを実行したら↓
Assets/Script/Chapter10/AttackArea.cs(49,12): error CS1061: Type UnityEngine.Component' does not contain a definition for
enabled' and no extension method enabled' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
これと↓
Assets/Script/Chapter10/AttackArea.cs(56,12): error CS1061: Type UnityEngine.Component' does not contain a definition for
enabled' and no extension method enabled' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
の二つです。
追記
上記のスクリプトを以下のスクリプトにしてみましたが、現状変わらず(T ^ T)
C#
1using UnityEngine; 2using System.Collections; 3 4public class AttackArea : MonoBehaviour { 5 CharacterStatus status; 6 7 void Start() 8 { 9 status = transform.root.GetComponent<CharacterStatus>(); 10 } 11 12 13 public class AttackInfo 14 { 15 public int attackPower; // この攻撃の攻撃力. 16 public Transform attacker; // 攻撃者. 17 } 18 19 20 // 攻撃情報を取得する. 21 AttackInfo GetAttackInfo() 22 { 23 AttackInfo attackInfo = new AttackInfo(); 24 // 攻撃力の計算. 25 attackInfo.attackPower = status.Power; 26 // 攻撃強化中 27 if (status.powerBoost) 28 attackInfo.attackPower += attackInfo.attackPower; 29 30 attackInfo.attacker = transform.root; 31 32 return attackInfo; 33 } 34 35 // 当たった. 36 void OnTriggerEnter(Collider other) 37 { 38 // 攻撃が当たった相手のDamageメッセージをおくる. 39 other.SendMessage("Damage",GetAttackInfo()); 40 // 攻撃した対象を保存. 41 status.lastAttackTarget = other.transform.root.gameObject; 42 } 43 44 45 // 攻撃判定を有効にする. 46 void OnAttack() 47 { 48 GetComponent<Collider> ().enable = true; 49 } 50 51 52 // 攻撃判定を無効にする. 53 void OnAttackTermination() 54 { 55 GetComponent<Collider> ().enable = false; 56 } 57} 58

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/12 11:43
2017/01/12 12:18