敵の攻撃を作る①(一定時間ごとに砲弾を発射する)











敵が一定時間ごとに砲弾を発射する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyShotShell : MonoBehaviour
{
public GameObject enemyShellPrefab;
public float shotSpeed;
public AudioClip shotSound;
private int shotIntarval;
void Update()
{
shotIntarval += 1;
if (shotIntarval % 60 == 0)
{
GameObject enemyShell = Instantiate(enemyShellPrefab, transform.position, Quaternion.identity);
Rigidbody enemyShellRb = enemyShell.GetComponent<Rigidbody>();
// forwardはZ軸方向(青軸方向)・・・>この方向に力を加える。
enemyShellRb.AddForce(transform.forward * shotSpeed);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
Destroy(enemyShell, 3.0f);
}
}
}







BattleTank(基礎/全31回)
他のコースを見る










敵が一定時間ごとに砲弾を発射する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyShotShell : MonoBehaviour
{
public GameObject enemyShellPrefab;
public float shotSpeed;
public AudioClip shotSound;
private int shotIntarval;
void Update()
{
shotIntarval += 1;
if (shotIntarval % 60 == 0)
{
GameObject enemyShell = Instantiate(enemyShellPrefab, transform.position, Quaternion.identity);
Rigidbody enemyShellRb = enemyShell.GetComponent<Rigidbody>();
// forwardはZ軸方向(青軸方向)・・・>この方向に力を加える。
enemyShellRb.AddForce(transform.forward * shotSpeed);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
Destroy(enemyShell, 3.0f);
}
}
}







敵の攻撃を作る①(一定時間ごとに砲弾を発射する)