質問編集履歴

3

書式の修正

2016/07/28 17:46

投稿

horitomo
horitomo

スコア26

test CHANGED
File without changes
test CHANGED
@@ -50,9 +50,15 @@
50
50
 
51
51
  }
52
52
 
53
+ ```
54
+
55
+
56
+
53
- ////////////////////////////////////////////////////////////////////////////////////////
57
+ ```C#
54
58
 
55
59
  public class Wepon : MonoBehaviour//Sw_Qbのプレハブに追加
60
+
61
+
56
62
 
57
63
  {
58
64
 
@@ -106,8 +112,8 @@
106
112
 
107
113
  }
108
114
 
109
-
115
+ ```
110
116
 
111
- ```
117
+
112
118
 
113
119
  これで何とか動作しました!!

2

書式の改善

2016/07/28 17:46

投稿

horitomo
horitomo

スコア26

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,10 @@
28
28
 
29
29
  (**以下、追記)
30
30
 
31
+ ```C#
32
+
33
+
34
+
31
35
 
32
36
 
33
37
  public class Mycontrol : MonoBehaviour {//自キャラコントロールスクリプト
@@ -39,8 +43,6 @@
39
43
  public GameObject Sw_Qb_POS = null;//攻撃判定用キューブの生成される位置の親のオブジェクト(この場合は、剣)
40
44
 
41
45
  //(中略)
42
-
43
-
44
46
 
45
47
  void Attack() { MakeCollider(); }//Attackアニメーションのイベント→当たり判定を呼び出す(スクリプト的には意味ないけど一応書く)
46
48
 
@@ -106,6 +108,6 @@
106
108
 
107
109
 
108
110
 
109
-
111
+ ```
110
112
 
111
113
  これで何とか動作しました!!

1

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

2016/07/28 17:41

投稿

horitomo
horitomo

スコア26

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,89 @@
23
23
  初歩的な質問で申し訳ないですがよろしくおねがいします。
24
24
 
25
25
  スクリプトはC♯で返答いただけるとありがたいです。
26
+
27
+
28
+
29
+ (**以下、追記)
30
+
31
+
32
+
33
+ public class Mycontrol : MonoBehaviour {//自キャラコントロールスクリプト
34
+
35
+ CharacterController characterController;
36
+
37
+ public GameObject Sw_Qb = null;//攻撃判定用キューブ
38
+
39
+ public GameObject Sw_Qb_POS = null;//攻撃判定用キューブの生成される位置の親のオブジェクト(この場合は、剣)
40
+
41
+ //(中略)
42
+
43
+
44
+
45
+ void Attack() { MakeCollider(); }//Attackアニメーションのイベント→当たり判定を呼び出す(スクリプト的には意味ないけど一応書く)
46
+
47
+ void MakeCollider() { GameObject.Instantiate(Sw_Qb, Sw_Qb_POS.transform.position, Quaternion.identity); //攻撃判定用のCubeCollider生成
48
+
49
+ }
50
+
51
+ ////////////////////////////////////////////////////////////////////////////////////////
52
+
53
+ public class Wepon : MonoBehaviour//Sw_Qbのプレハブに追加
54
+
55
+ {
56
+
57
+ public int Power = 50; //攻撃力
58
+
59
+ private float time = 0;
60
+
61
+ public float interbal =0.5f; //攻撃判定残留時間
62
+
63
+
64
+
65
+ // Use this for initialization
66
+
67
+ // Update is called once per frame
68
+
69
+ void Update()
70
+
71
+ {
72
+
73
+ time += Time.deltaTime;
74
+
75
+ if (time > interbal) { Destroy(this.gameObject); }
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+ }
84
+
85
+ void OnTriggerEnter(Collider col)//ぶつかった時実行
86
+
87
+ {
88
+
89
+
90
+
91
+
92
+
93
+ if (col.gameObject.tag == "Enemy")//Enemyとだったら
94
+
95
+ {
96
+
97
+ col.gameObject.SendMessage("Damage", Power);//ダメージを与える
98
+
99
+ col.gameObject.SendMessage("sw_ef");//斬撃エフェクトを与える
100
+
101
+
102
+
103
+ }
104
+
105
+ }
106
+
107
+
108
+
109
+
110
+
111
+ これで何とか動作しました!!