質問編集履歴
1
コードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -49,3 +49,139 @@
|
|
49
49
|
|
50
50
|
|
51
51
|
よろしくお願いいたします。
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
追記です。こういうコードを書いていたのですが、動きが不自然となってしましました。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
ーー
|
60
|
+
|
61
|
+
using System.Collections;
|
62
|
+
|
63
|
+
using System.Collections.Generic;
|
64
|
+
|
65
|
+
using UnityEngine;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
public class missile2_src : MonoBehaviour
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
public GameObject target; //ミサイルのターゲットをセット
|
74
|
+
|
75
|
+
public float Forward_speed =10f;
|
76
|
+
|
77
|
+
public float h_time = 1.5f; //まっすぐ進む時間
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public float missile_Look_speed = 0.03f;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
bool stop_f = false;
|
86
|
+
|
87
|
+
bool homing_f = false;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// 出現させるエフェクト
|
92
|
+
|
93
|
+
[SerializeField] private GameObject effectObject;
|
94
|
+
|
95
|
+
// エフェクトを消す秒数
|
96
|
+
|
97
|
+
[SerializeField] private float deleteTime;
|
98
|
+
|
99
|
+
// エフェクトの出現位置のオフセット値
|
100
|
+
|
101
|
+
[SerializeField] private float offset;
|
102
|
+
|
103
|
+
void Start()
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
transform.rotation = Quaternion.Euler(-90,0, 0);
|
108
|
+
|
109
|
+
Invoke("homing_on", h_time);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
void Update()
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
if (stop_f == false)
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
transform.position += transform.forward * Forward_speed;
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if (homing_f)
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
float step = Time.deltaTime * Forward_speed;
|
138
|
+
|
139
|
+
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, step);
|
140
|
+
|
141
|
+
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(target.transform.position - this.transform.position), missile_Look_speed);
|
142
|
+
|
143
|
+
transform.position += transform.forward * Time.deltaTime * Forward_speed *50f;//このスピードだと遅いため、数十倍している
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
void homing_on()
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
stop_f = true;
|
158
|
+
|
159
|
+
homing_f = true;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
void OnTriggerEnter(Collider col)
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
Vector3 hitPos = col.ClosestPointOnBounds(this.transform.position);
|
172
|
+
|
173
|
+
var instantiateEffect = GameObject.Instantiate(effectObject, hitPos + new Vector3(0f, offset, 0f), Quaternion.identity) as GameObject;
|
174
|
+
|
175
|
+
Destroy(instantiateEffect, deleteTime);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
homing_f = false;
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
Destroy(this.gameObject, deleteTime);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|