real quick

what does EOF mean. it keeps poppin expecting EOF, found ‘else’.

It probably means your syntax for your script is incorrect. You probably have missing/extra a curly braces. It’s expecting the “End Of File” (EOF) and instead it finds more code. If you post your script file we can take a look at it.

first off im not a coding person by any means so if look horrible because it is.

function Fire () {
if (bulletsLeft == 0)
return;

// If there is more than one bullet between the last and this frame
// Reset the nextFireTime
if (Time.time - fireRate > nextFireTime)
nextFireTime = Time.time - Time.deltaTime;

// Keep firing until we used up the fire time
while( nextFireTime < Time.time bulletsLeft != 0) {
FireOneShot();
nextFireTime += fireRate;
}
}

// this is where im trying to get my gun reload by its self after it runs out of bullets

// reloading by itself
else (bulletsLeft ==0)
{
bulletsLeft+ 2 bullets =100;
}

This should eliminate that EOF error.

function Fire () {
    if (bulletsLeft == 0)
        return;

    // If there is more than one bullet between the last and this frame
    // Reset the nextFireTime
    if (Time.time - fireRate > nextFireTime)
    {
        nextFireTime = Time.time - Time.deltaTime;
        
        // Keep firing until we used up the fire time
        while( nextFireTime < Time.time  bulletsLeft != 0)
        {
            FireOneShot();
            nextFireTime += fireRate;
        }
    }
    
    // this is where im trying to get my gun reload by its self after it runs out of bullets

    // reloading by itself
    else {
        /*
        q-maja, I'm not sure what you were trying to do here.  Maybe just   bulletsLeft = 100;
        
        (bulletsLeft == 0)
        {
            bulletsLeft + 2 bullets =100;
        }
        */
    }
}

It’s always helpful to indent “if” statements and “while” statements, so you can keep track of what curly brackets you need to close. As you know, every one of these { needs a corresponding one of these } .

I put in a comment about your “reload” section.

EDIT: Ahhh, beat me to it Brett!

No problem, we’re all “not a coding person” until we become one! :smiley:

I see a few minor oversights with your code, first off:

if (Time.time - fireRate > nextFireTime)
    nextFireTime = Time.time - Time.deltaTime;

    // Keep firing until we used up the fire time
    while( nextFireTime < Time.time  bulletsLeft

Take note of line 2 there. Your starting IF statement does not have a curly brace after it. This means that the IF condition only applies to the next line. I’m guessing you know that because you use this behaviour in your top-most IF statement (bulletsLeft == 0, return) so just add a curly brace there and you’re good.

Secondly, your “else” condition should be “else if”:

 else (bulletsLeft ==0) 
//change to:
else if (bulletsLeft ==0)

IF conditions always run in the form of:

If (CONDITION)
{
}
else if (CONDITION)
{
}
else if (CONDITION)
{
}
...//more else if conditions
}
else //no condition, only happens if no other condition above it is satisfied
{
}

Finally, your last line there: “bulletsLeft+ 2 bullets =100;” doesn’t appear valid. I’m not sure what you’re trying to achieve there (is it adding 2 bullets per frame? Resetting to a full magazine of 100 bullets?)

Beyond those, I don’t see any other issues

One suggestion I might make is to always use curly braces even for IF conditions that have only one line. So instead of:

if (bulletsLeft == 0)
return;

You would write

if (bulletsLeft == 0)
{
    return;
}

Even though it’s up to personal preference and both forms are valid, if you’re learning programming, it helps to have a solid, consistent structure with nicely paragraphed (indented) code. It will help a lot with spotting out issues like these. Keep plugging along!

@FizixMan I may have “beaten you to it” but your explanations were very educational!

thank you 2 very much the peice of code you seen was machine gun from one fps tutorial and im modifying it so i can use as for restraint for my gravity gun in my game. But thanks again. Ummm… you 2 wouldnt know how to implement a raycasting system would you?

Raycasting for rendering or for hit detection?

detection im using the look at script and it works somewhat but i need something more acurate. more 1 to 1 ratio.

I haven’t done much work (mostly a bit of experimentation) with hit detection, but I think if you give your objects a physics collider, you can use methods like “Physics.Raycast” to do so. For more information, take a peek at Unity - Scripting API: Physics.Raycast

appreciate it man