弾を生成する方法は別途考えてね、という趣旨の記事なのでしょう。(本の内容を受けての記事なので元ネタの「Unity4.6/5.0でつくる 2Dゲーム制作入門 [改訂第二版]」の内容を長々とコピペするのは権利的にどうか、という配慮なのだと思います)
Bulletはおそらく、というか間違いなくUnityのGameObjectに張り付いている(MonoBehaviour)Componentなので、残念ながらBeatStarさんの提示された方法ではうまくいきません。
newすると実行時警告が出るでしょうし、実際弾も表示されません。
元サイトに乗っているソースは上述の配慮から不完全で、おそらく、
Bullet.cs
1public class Bullet : MonoBehaviour
2{
3 float direction;
4 float speed;
5
6 void Update()
7 {
8 transform.position += new Vector3(Mathf.Sin(direction), Mathf.Cos(direction), 0) * speed * Time.deltaTime;
9 }
10
11 public static Bullet Add(GameObject prefab, float x, float y, float direction, float speed)
12 {
13 var bullet = ((GameObject)Instantiate(prefab, new Vector3(x, y, 0))).GetComponent<Bullet>();
14 bullet.direction = direction;
15 bullet.speed= speed;
16 return bullet;
17 }
18}
Enemy.cs
1public class Enemy : MonoBehaviour
2{
3 public GameObject bulletPrefab;
4
5 // ~略~
6
7 for (int index = -3; index < 3; index++)
8 {
9 Bullet.Add(bulletPrefab, transform.position.x, transform.position.y, dir + index * 30 + 15, 3);
10 }
11}
このようなものだったのだろうと思います。(あくまで推測です!)
やはり、Unity4.6/5.0でつくる 2Dゲーム制作入門 [改訂第二版]を購入されて読まれたほうがいいのではと思います。(たったの500円ですし)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。