using System.Collections; using System.Collections.Generic; using UnityEngine; public class Shot : MonoBehaviour { public GameObject bullet; public Transform muzzle; public float speed = 1000; void Update() { if (Input.GetButtonDown("Fire1")) { StartCoroutine("shot"); } } IEnumerator shot() { GameObject bullets = GameObject.Instantiate(bullet) as GameObject; yield return new WaitForSeconds(0.5f); Vector3 force; force = this.gameObject.transform.forward * speed; bullets.GetComponent<Rigidbody>().AddForce(force); bullets.transform.position = muzzle.position; } }
左クリックで弾を飛ばす
2019年5月3日
コメント
コメント一覧 (1件)
[…] クリックで弾を飛ばす […]