ミサイルの発射②(ミサイルスクリプトの作成)

ミサイルの発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireMissile : MonoBehaviour
{
public GameObject missilePrefab;
public float speed;
public AudioClip sound;
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
GameObject missile = Instantiate(missilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * speed);
AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);
Destroy(missile, 2.0f);
}
}
}








【2021版】Danmaku(基礎/全55回)
他のコースを見る
ミサイルの発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireMissile : MonoBehaviour
{
public GameObject missilePrefab;
public float speed;
public AudioClip sound;
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
GameObject missile = Instantiate(missilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * speed);
AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);
Destroy(missile, 2.0f);
}
}
}








ミサイルの発射②(ミサイルスクリプトの作成)