手榴弾を投げる




手榴弾を投げる
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThrowGrenade : MonoBehaviour { public GameObject grenadePrefab; public AudioClip throwSound; public float throwSpeed; public int grenadeCount; void Update () { if(Input.GetKeyDown(KeyCode.Mouse0) && grenadeCount > 0){ grenadeCount -= 1; GameObject grenade = (GameObject)Instantiate(grenadePrefab, transform.position, Quaternion.identity); Rigidbody grenadeRb = grenade.GetComponent<Rigidbody>(); grenadeRb.AddForce(transform.forward * throwSpeed); AudioSource.PlayClipAtPoint(throwSound, Camera.main.transform.position); } } }
C#




EscapeCombat
他のコースを見る



手榴弾を投げる
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThrowGrenade : MonoBehaviour { public GameObject grenadePrefab; public AudioClip throwSound; public float throwSpeed; public int grenadeCount; void Update () { if(Input.GetKeyDown(KeyCode.Mouse0) && grenadeCount > 0){ grenadeCount -= 1; GameObject grenade = (GameObject)Instantiate(grenadePrefab, transform.position, Quaternion.identity); Rigidbody grenadeRb = grenade.GetComponent<Rigidbody>(); grenadeRb.AddForce(transform.forward * throwSpeed); AudioSource.PlayClipAtPoint(throwSound, Camera.main.transform.position); } } }
C#




手榴弾を投げる