左クリックで弾を飛ばす

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;
            }
    }
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

コメント

コメント一覧 (1件)

小学生でもわかるUnity | ゲタバコ倶楽部 へ返信する コメントをキャンセル

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

目次