ショットガンを撃つ
![2460e3c7 7298 41f7 b2bc cf3f1a07bf41](https://codegenius.org/uploads/slide/image/2924/2460e3c7-7298-41f7-b2bc-cf3f1a07bf41.jpeg)
![7e6c473a 70d0 443f 97d4 304892878487](https://codegenius.org/uploads/slide/image/2925/7e6c473a-70d0-443f-97d4-304892878487.jpeg)
ショットガンの実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotBullet : MonoBehaviour {
public GameObject bulletPrefab;
public AudioClip shotSound;
public AudioClip reloadSound;
public float shotSpeed;
public int shotCount = 30;
private float shotInterval;
void Update () {
if (Input.GetKey (KeyCode.Mouse0)) {
shotInterval += 1;
if (shotInterval % 5 == 0 && shotCount > 0) {
shotCount -= 1;
GameObject bullet = (GameObject)Instantiate (bulletPrefab, transform.position, Quaternion.Euler (transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
Rigidbody bulletRb = bullet.GetComponent<Rigidbody> ();
bulletRb.AddForce (transform.forward * shotSpeed);
Destroy (bullet, 3.0f);
AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position);
}
} else if (Input.GetKeyDown (KeyCode.R)) {
shotCount = 30;
AudioSource.PlayClipAtPoint (reloadSound, Camera.main.transform.position);
}
}
}
![F9c9d4ad 1fb1 442d 92aa 9153da7507b9](https://codegenius.org/uploads/slide/image/2926/f9c9d4ad-1fb1-442d-92aa-9153da7507b9.jpeg)
![F4cbdf6e 8fc6 4622 be80 070dae83384a](https://codegenius.org/uploads/slide/image/2927/f4cbdf6e-8fc6-4622-be80-070dae83384a.jpeg)
![053da27d 4c50 4efc abff 393958b5e89f](https://codegenius.org/uploads/slide/image/2928/053da27d-4c50-4efc-abff-393958b5e89f.jpeg)
EscapeCombat
他のコースを見る![2460e3c7 7298 41f7 b2bc cf3f1a07bf41](https://codegenius.org/uploads/slide/image/2924/2460e3c7-7298-41f7-b2bc-cf3f1a07bf41.jpeg)
![7e6c473a 70d0 443f 97d4 304892878487](https://codegenius.org/uploads/slide/image/2925/7e6c473a-70d0-443f-97d4-304892878487.jpeg)
ショットガンの実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotBullet : MonoBehaviour {
public GameObject bulletPrefab;
public AudioClip shotSound;
public AudioClip reloadSound;
public float shotSpeed;
public int shotCount = 30;
private float shotInterval;
void Update () {
if (Input.GetKey (KeyCode.Mouse0)) {
shotInterval += 1;
if (shotInterval % 5 == 0 && shotCount > 0) {
shotCount -= 1;
GameObject bullet = (GameObject)Instantiate (bulletPrefab, transform.position, Quaternion.Euler (transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
Rigidbody bulletRb = bullet.GetComponent<Rigidbody> ();
bulletRb.AddForce (transform.forward * shotSpeed);
Destroy (bullet, 3.0f);
AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position);
}
} else if (Input.GetKeyDown (KeyCode.R)) {
shotCount = 30;
AudioSource.PlayClipAtPoint (reloadSound, Camera.main.transform.position);
}
}
}
![F9c9d4ad 1fb1 442d 92aa 9153da7507b9](https://codegenius.org/uploads/slide/image/2926/f9c9d4ad-1fb1-442d-92aa-9153da7507b9.jpeg)
![F4cbdf6e 8fc6 4622 be80 070dae83384a](https://codegenius.org/uploads/slide/image/2927/f4cbdf6e-8fc6-4622-be80-070dae83384a.jpeg)
![053da27d 4c50 4efc abff 393958b5e89f](https://codegenius.org/uploads/slide/image/2928/053da27d-4c50-4efc-abff-393958b5e89f.jpeg)
ショットガンを撃つ