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

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

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

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

Q&A

解決済

2回答

19284閲覧

error CS1061が出てしまい困っています

zenbo0114

総合スコア53

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

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

0グッド

0クリップ

投稿2017/01/12 11:27

編集2017/01/12 11:59

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

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

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

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

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

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

guest

回答2

0

ベストアンサー

おそらくUnity4準拠の本を参考にされているのだと思いますが、Unity5からは GetComponent<Collider>().enable と GetComponentを介して取得する必要があります。

追記
コメントにも書きましたが、Colliderのプロパティ名が間違っていたようですね。正しくは以下の通りでした。
x enable
o enabled
https://docs.unity3d.com/ja/current/ScriptReference/Collider-enabled.html

投稿2017/01/12 11:37

編集2017/01/16 08:09
kanitaoru

総合スコア204

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

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

zenbo0114

2017/01/12 11:43

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; // 攻撃強化中 if (status.powerBoost) attackInfo.attackPower += attackInfo.attackPower; attackInfo.attacker = transform.root; return attackInfo; } // 当たった. void OnTriggerEnter(Collider other) { // 攻撃が当たった相手のDamageメッセージをおくる. other.SendMessage("Damage",GetAttackInfo()); // 攻撃した対象を保存. status.lastAttackTarget = other.transform.root.gameObject; } // 攻撃判定を有効にする. void OnAttack() { GetComponent<Collider> ().enable = true; } // 攻撃判定を無効にする. void OnAttackTermination() { GetComponent<Collider> ().enable = false; } } としてみましたが、変りませんでした
guest

0

このソースを見る限り、colliderが定義されていないかと思います。
GetComponent などで設定してみてください。

投稿2017/01/12 11:37

Kapustin

総合スコア1186

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問