Shooting.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shooting : MonoBehaviour {


    public GameObject bullet;
    public Transform muzzle;
    public float speed = 1000;


    void Start()
    {

    }

    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;
            }
    }
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.