敵の攻撃⑤(スパイラル弾)






スパイラル弾
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissileB : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float speed;
private int timeCount;
void Update()
{
timeCount += 1;
if(timeCount % 5 == 0)
{
GameObject missile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * speed);
Destroy(missile, 10f);
}
// ★追加
// timeCountが500になった時、このオブジェクトにRotateスクリプトを付加する。
// 同時にRotation Yに90を設定する。
if(timeCount == 500)
{
this.gameObject.AddComponent<Rotate>().pos = new Vector3(0, 90, 0);
}
}
}

【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る





スパイラル弾
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissileB : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float speed;
private int timeCount;
void Update()
{
timeCount += 1;
if(timeCount % 5 == 0)
{
GameObject missile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * speed);
Destroy(missile, 10f);
}
// ★追加
// timeCountが500になった時、このオブジェクトにRotateスクリプトを付加する。
// 同時にRotation Yに90を設定する。
if(timeCount == 500)
{
this.gameObject.AddComponent<Rotate>().pos = new Vector3(0, 90, 0);
}
}
}

敵の攻撃⑤(スパイラル弾)