Allied shoot tag enemy don't work.

Hello. I wrote a script following the precise instructions on a YouTube tutorial for a friend to shoot enemies with the enemy tag but nevertheless gives me many errors.
A premise: I compiled the script by carefully following the tutorial and examining the code line by line and I carefully wrote the code strings that I found in the tutorial. I’m making a 3D shooter where there are allied soldiers who shoot everyone who has the enemy tag.

The errors are there and I can’t really fix them:

Assets / AlliedShooting.cs (48,26): error CS1547: Keyword void 'cannot be used in this context Assets / AlliedShooting.cs (48,27): error CS1525: Unexpected symbol (‘, expecting)', , ‘,;', [’, or` =’
Assets / AlliedShooting.cs (54,1): error CS8025: Parsing error

Here are the errors. My script is the following. I hope someone can correct the script because I am not able to do it. Thanks in advance.

using UnityEngine;
using System.Collections;

public class AlliedShooting : MonoBehaviour {



    [SerializeField]
    GameObject projectile;

    [SerializeField]
    Transform shootPoint;

    [SerializeField]
    float turnSpeed = 5;

    Transform target;
    float fireRate = 0.3f;




    // Use this for initialization
    private void Start () {

        target = GameObject.FindGameObjectsWithTag ("enemy").transform;

   
    }
   
    // Update is called once per frame
    private void Update () {

        fireRate -= Time.deltaTime;

        Vector3 direction = target.position - transform.position;
        trasform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), turnSpeed * Time.deltaTime);

        if(fireRate <= 0)

        {
            Shoot();

        }
    


        void Shoot();
        {
            Instantiate(projectile, shootPoint.position, shootPoint.rotation);
        }
    }
}
}
}

You declared the “Shoot” function inside your “Update” Loop which is not right,
it should be declared outside of it.

Also, if you declare a function, then without the " ; " symbol :wink:

1 Like