ビーム弾を発射する




ビーム弾の発射
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShotBeam : MonoBehaviour { public GameObject laserGun; public GameObject beamPrefab; public AudioClip shotSound; public float shotSpeed; void Update() { // マウス左クリックで発射 if(Input.GetMouseButtonDown(0)) { GameObject beam = Instantiate(beamPrefab, transform.position, laserGun.transform.rotation); Rigidbody beamRb = beam.GetComponent<Rigidbody>(); beamRb.AddForce(transform.forward * shotSpeed); AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position); } } }
C#




【2021版】X_Mission(全34回)
他のコースを見る



ビーム弾の発射
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShotBeam : MonoBehaviour { public GameObject laserGun; public GameObject beamPrefab; public AudioClip shotSound; public float shotSpeed; void Update() { // マウス左クリックで発射 if(Input.GetMouseButtonDown(0)) { GameObject beam = Instantiate(beamPrefab, transform.position, laserGun.transform.rotation); Rigidbody beamRb = beam.GetComponent<Rigidbody>(); beamRb.AddForce(transform.forward * shotSpeed); AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position); } } }
C#




ビーム弾を発射する