ビーム弾を発射する
ビーム弾の発射
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);
}
}
}
【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);
}
}
}
ビーム弾を発射する