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;
}
}