I have a script and whenever I hit the “Fire1” button, it doesn’t work.
Whats currently happening is its firing one bullet and then firing it again in a second.
Here is my script:
using UnityEngine;
using System.Collections;
public class FireWeapon : MonoBehaviour
{
public float fireRate = 0f;
public Rigidbody bullet;
public float speed = 0f;
void Update ()
{
if (Input.GetButtonDown ("Fire1"))
{
InvokeRepeating("Fire", 1f, fireRate);
}
}
void Fire ()
{
Rigidbody pel = Instantiate (bullet, transform.position, transform.rotation) as Rigidbody;
pel.AddForce (transform.forward * speed);
}
}
I got that from my code, it should shoot like every 1 second, change to your liking, I hope that works for you! P.S. - Change the FX120P to whatever your gameobject is called.