making enemy shoot script problem

I would like this script to continuously shoot a rigid body at the player.How would i do that?

using UnityEngine;
using System.Collections;

public class Enemyfireprojectile : MonoBehaviour {
    public Rigidbody projectile;
    void Update() {

            Rigidbody clone;
            clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
            clone.velocity = transform.TransformDirection(Vector3.forward * 90);
        }
    }
{

I would remove that from the Update() function as it would shoot every frame.

using UnityEngine;
using System.Collections;
public class Enemyfireprojectile : MonoBehaviour {
public Transform target; //this is the rigidbody you want the object to shoot at
bool isShooting = false;
public Rigidbody projectile;
void Update() {
    if(!isShooting)
    {       
        StartCoroutine(shoot());
    }
}
IEnumerator shoot()
{
    Rigidbody clone;
    transform.LookAt(target)
    isShooting = true;
    clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
    clone.velocity = transform.TransformDirection(Vector3.forward); //this might be wrong
    yield return new WaitForSeconds(1/15); //rate of fire
    isShooting = false;
}

I can’t test it right now but it should work.

I have the basic version of unity not the pro version.

How does that have anything to do with the script he gave you?

His script is a little buggy but if you changed the name from

IEnumerator shot() to IEnumerator shoot()

It might work as intended.

it works because you are not firing every frame. By using an IEnermator (coroutine) you stop the bullet from being fired every frame, and force it to wait for 1/15 seconds to be able to shoot again.

Well from what it looks like your not even aiming at the player to begin with…

But if you want a countinous stream of bullets use yeild.waitforseconds.

I get a unexpected symbol error on line 47.

My code is 23 lines long, you have to post the entire script.

It had many errors.

using UnityEngine;


using System.Collections;


public class Enemyfireprojectile : MonoBehaviour {
   
   
public Transform target; //this is the rigidbody you want the object to shoot at
       
       
bool isShooting = false;
       
       
public Rigidbody projectile;
       
       
void Update() {
           
           
        if(!isShooting)
        {         
               
               
        StartCoroutine(shoot());
               
               
        }
           
           
   }
IEnumerator shoot()
{
        Rigidbody clone;
        transform.LookAt(target);
        isShooting = true;
        clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
        clone.velocity = transform.TransformDirection(Vector3.forward); //this might be wrong
        yield return new WaitForSeconds(1/15); //rate of fire
        isShooting = false;
           
           
}
       
{

Delete { at line 47

Okay thakyou I corrected the mistakes.There were two.

No problems!