Enemyの球をとばす
Enemyオブジェクトも球を飛ばせるようにする。
EnemyMove.csで、
初期設定に
public GameObject prefab; //プレファブ設定
一番下の}の前に
//キャラクター読み込み
GameObject LoadBullet(){
GameObject bullet = GameObject.Instantiate(prefab) as GameObject;
return bullet;
}
void attacking(){}の中に
GameObject bullet = LoadBullet();
を入れる。
Hierarchy>Enemyを選択して
Inspector>EnemyMoveのPrefabを、EnemyBulletとする
ゲームを起動して、
Inspector>EnemyMoveのEnemyStateをAttackingにすると
そうすると無尽蔵にEnemyBullet(Clone)というオブジェクトが増殖する
Project>Prefabs>EnemyBullet
にある
AddComponent>PhysicsのRigidbodyをつける
private int bulletSpeed=5; //追記
GameObject LoadBullet(){}に追記
Vector3 pForward = transform.TransformDirection(Vector3.forward); //オブジェクトの正面の情報を得る
pForward.y = 1;//高さ設定
bullet.transform.position = transform.position + pForward; //Prefabの座標
bullet.GetComponent
().velocity = pForward*bulletSpeed;
void attacking(){}のGameObject bullet = LoadBullet();を
if (enemyTime <= 0) {
GameObject bullet = LoadBullet();
}
に変更。
- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2016/10/31(月) 18:00:00|
- Unity
-
| トラックバック:0
-
| コメント:0