teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

書式の修正

2016/07/28 17:46

投稿

horitomo
horitomo

スコア26

title CHANGED
File without changes
body CHANGED
@@ -24,8 +24,11 @@
24
24
  void Attack() { MakeCollider(); }//Attackアニメーションのイベント→当たり判定を呼び出す(スクリプト的には意味ないけど一応書く)
25
25
  void MakeCollider() { GameObject.Instantiate(Sw_Qb, Sw_Qb_POS.transform.position, Quaternion.identity); //攻撃判定用のCubeCollider生成
26
26
  }
27
+ ```
28
+
27
- ////////////////////////////////////////////////////////////////////////////////////////
29
+ ```C#
28
30
  public class Wepon : MonoBehaviour//Sw_Qbのプレハブに追加
31
+
29
32
  {
30
33
  public int Power = 50; //攻撃力
31
34
  private float time = 0;
@@ -52,6 +55,6 @@
52
55
 
53
56
  }
54
57
  }
55
-
56
- ```
58
+ ```
59
+
57
60
  これで何とか動作しました!!

2

書式の改善

2016/07/28 17:46

投稿

horitomo
horitomo

スコア26

title CHANGED
File without changes
body CHANGED
@@ -13,13 +13,14 @@
13
13
  スクリプトはC♯で返答いただけるとありがたいです。
14
14
 
15
15
  (**以下、追記)
16
+ ```C#
16
17
 
18
+
17
19
  public class Mycontrol : MonoBehaviour {//自キャラコントロールスクリプト
18
20
  CharacterController characterController;
19
21
  public GameObject Sw_Qb = null;//攻撃判定用キューブ
20
22
  public GameObject Sw_Qb_POS = null;//攻撃判定用キューブの生成される位置の親のオブジェクト(この場合は、剣)
21
23
  //(中略)
22
-
23
24
  void Attack() { MakeCollider(); }//Attackアニメーションのイベント→当たり判定を呼び出す(スクリプト的には意味ないけど一応書く)
24
25
  void MakeCollider() { GameObject.Instantiate(Sw_Qb, Sw_Qb_POS.transform.position, Quaternion.identity); //攻撃判定用のCubeCollider生成
25
26
  }
@@ -52,5 +53,5 @@
52
53
  }
53
54
  }
54
55
 
55
-
56
+ ```
56
57
  これで何とか動作しました!!

1

教えていただいたアニメーションからイベント設定をしたことを用いたスクリプトの追記

2016/07/28 17:41

投稿

horitomo
horitomo

スコア26

title CHANGED
File without changes
body CHANGED
@@ -10,4 +10,47 @@
10
10
  これに対して、剣colliderをプレハブ化して、攻撃中のみ剣の位置にspawnさせるという様にするのが良いのでしょうか??
11
11
 
12
12
  初歩的な質問で申し訳ないですがよろしくおねがいします。
13
- スクリプトはC♯で返答いただけるとありがたいです。
13
+ スクリプトはC♯で返答いただけるとありがたいです。
14
+
15
+ (**以下、追記)
16
+
17
+ public class Mycontrol : MonoBehaviour {//自キャラコントロールスクリプト
18
+ CharacterController characterController;
19
+ public GameObject Sw_Qb = null;//攻撃判定用キューブ
20
+ public GameObject Sw_Qb_POS = null;//攻撃判定用キューブの生成される位置の親のオブジェクト(この場合は、剣)
21
+ //(中略)
22
+
23
+ void Attack() { MakeCollider(); }//Attackアニメーションのイベント→当たり判定を呼び出す(スクリプト的には意味ないけど一応書く)
24
+ void MakeCollider() { GameObject.Instantiate(Sw_Qb, Sw_Qb_POS.transform.position, Quaternion.identity); //攻撃判定用のCubeCollider生成
25
+ }
26
+ ////////////////////////////////////////////////////////////////////////////////////////
27
+ public class Wepon : MonoBehaviour//Sw_Qbのプレハブに追加
28
+ {
29
+ public int Power = 50; //攻撃力
30
+ private float time = 0;
31
+ public float interbal =0.5f; //攻撃判定残留時間
32
+
33
+ // Use this for initialization
34
+ // Update is called once per frame
35
+ void Update()
36
+ {
37
+ time += Time.deltaTime;
38
+ if (time > interbal) { Destroy(this.gameObject); }
39
+
40
+
41
+
42
+ }
43
+ void OnTriggerEnter(Collider col)//ぶつかった時実行
44
+ {
45
+
46
+
47
+ if (col.gameObject.tag == "Enemy")//Enemyとだったら
48
+ {
49
+ col.gameObject.SendMessage("Damage", Power);//ダメージを与える
50
+ col.gameObject.SendMessage("sw_ef");//斬撃エフェクトを与える
51
+
52
+ }
53
+ }
54
+
55
+
56
+ これで何とか動作しました!!