ライフル弾を発射する


ライフル弾を発射する
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShotBullet : MonoBehaviour { public GameObject bulletPrefab; public AudioClip shotSound; public float shotSpeed; void Update () { // スペースキーで発射できるようにします。 if (Input.GetKeyDown (KeyCode.Space)) { // (ポイント)ライフル弾の生成「角度」を「親の角度(向き)」と一致させる。 // この意味を考えてみましょう! 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); AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position); Destroy (bullet, 2.0f); } } }
C#





EscapeCombat(メモ)
他のコースを見る

ライフル弾を発射する
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShotBullet : MonoBehaviour { public GameObject bulletPrefab; public AudioClip shotSound; public float shotSpeed; void Update () { // スペースキーで発射できるようにします。 if (Input.GetKeyDown (KeyCode.Space)) { // (ポイント)ライフル弾の生成「角度」を「親の角度(向き)」と一致させる。 // この意味を考えてみましょう! 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); AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position); Destroy (bullet, 2.0f); } } }
C#





ライフル弾を発射する