敵ミサイルの発射
![46859aa6 bac3 4195 8ef7 bcc4159c5d7d](https://codegenius.org/uploads/slide/image/1237/46859aa6-bac3-4195-8ef7-bcc4159c5d7d.jpeg)
![2faf4ccc f965 4d0a bfba d9e0d5daf585](https://codegenius.org/uploads/slide/image/1238/2faf4ccc-f965-4d0a-bfba-d9e0d5daf585.jpeg)
![56db9362 c978 4d49 a9fb c665c75e124e](https://codegenius.org/uploads/slide/image/1239/56db9362-c978-4d49-a9fb-c665c75e124e.jpeg)
![D126e556 c322 42d7 882c 578432b540c0](https://codegenius.org/uploads/slide/image/1240/d126e556-c322-42d7-882c-578432b540c0.jpeg)
敵のミサイルの発射(一定間隔)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissile : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float missileSpeed;
private int timeCount = 0;
void Update()
{
timeCount += 1;
// 「%」と「==」の意味を復習しましょう!(ポイント)
if (timeCount % 60 == 0)
{
// 敵のミサイルを生成する
GameObject enemyMissile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody enemyMissileRb = enemyMissile.GetComponent<Rigidbody>();
// ミサイルを飛ばす方向を決める。「forward」は「z軸」方向をさす(ポイント)
enemyMissileRb.AddForce(transform.forward * missileSpeed);
// 3秒後に敵のミサイルを削除する。
Destroy(enemyMissile, 3.0f);
}
}
}
![6b3d3639 99c6 4319 94c4 9c344c06cdda](https://codegenius.org/uploads/slide/image/1241/6b3d3639-99c6-4319-94c4-9c344c06cdda.jpeg)
![6cbad446 14bd 4fc4 8e30 915483eef185](https://codegenius.org/uploads/slide/image/1242/6cbad446-14bd-4fc4-8e30-915483eef185.jpeg)
![Bc3fea7c 5525 486d a31f 4ffb1f244074](https://codegenius.org/uploads/slide/image/1243/bc3fea7c-5525-486d-a31f-4ffb1f244074.jpeg)
![37d84880 943d 4ec3 8cf3 c55b8768df0b](https://codegenius.org/uploads/slide/image/1244/37d84880-943d-4ec3-8cf3-c55b8768df0b.jpeg)
Danmaku I(基礎1/全22回)
他のコースを見る![46859aa6 bac3 4195 8ef7 bcc4159c5d7d](https://codegenius.org/uploads/slide/image/1237/46859aa6-bac3-4195-8ef7-bcc4159c5d7d.jpeg)
![2faf4ccc f965 4d0a bfba d9e0d5daf585](https://codegenius.org/uploads/slide/image/1238/2faf4ccc-f965-4d0a-bfba-d9e0d5daf585.jpeg)
![56db9362 c978 4d49 a9fb c665c75e124e](https://codegenius.org/uploads/slide/image/1239/56db9362-c978-4d49-a9fb-c665c75e124e.jpeg)
![D126e556 c322 42d7 882c 578432b540c0](https://codegenius.org/uploads/slide/image/1240/d126e556-c322-42d7-882c-578432b540c0.jpeg)
敵のミサイルの発射(一定間隔)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissile : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float missileSpeed;
private int timeCount = 0;
void Update()
{
timeCount += 1;
// 「%」と「==」の意味を復習しましょう!(ポイント)
if (timeCount % 60 == 0)
{
// 敵のミサイルを生成する
GameObject enemyMissile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody enemyMissileRb = enemyMissile.GetComponent<Rigidbody>();
// ミサイルを飛ばす方向を決める。「forward」は「z軸」方向をさす(ポイント)
enemyMissileRb.AddForce(transform.forward * missileSpeed);
// 3秒後に敵のミサイルを削除する。
Destroy(enemyMissile, 3.0f);
}
}
}
![6b3d3639 99c6 4319 94c4 9c344c06cdda](https://codegenius.org/uploads/slide/image/1241/6b3d3639-99c6-4319-94c4-9c344c06cdda.jpeg)
![6cbad446 14bd 4fc4 8e30 915483eef185](https://codegenius.org/uploads/slide/image/1242/6cbad446-14bd-4fc4-8e30-915483eef185.jpeg)
![Bc3fea7c 5525 486d a31f 4ffb1f244074](https://codegenius.org/uploads/slide/image/1243/bc3fea7c-5525-486d-a31f-4ffb1f244074.jpeg)
![37d84880 943d 4ec3 8cf3 c55b8768df0b](https://codegenius.org/uploads/slide/image/1244/37d84880-943d-4ec3-8cf3-c55b8768df0b.jpeg)
敵ミサイルの発射