Home > database >  I'm having a problem with the message error CS1022: Type or namespace definition, or end-of-fil
I'm having a problem with the message error CS1022: Type or namespace definition, or end-of-fil

Time:05-15

I don't know why I get this error

Error CS1022: Type or namespace definition, or end-of-file expected

My code:

public class weaponcontroller : MonoBehaviour
{
    public gameobject sword1;
    public bool canAttack = true;
    public float attackcooldown = 1.0f;
    
    public void update();
    {
        if (input.getmousebuttondown(0))
        {
            if (canAttack)
            {
                swordAttack();
            } 
        }
    }

    public void swordAttack();
    {
        canAttack = false;
        animator anim = sword1.getcomponent<animator>();
        anim.settrigger("attack");
    }

    IEnumerator resetattackcooldown()
    {
        yield return new waitforseconds(attackcooldown);
        canAttack = true;
    }
}

CodePudding user response:

Do not put a semicolon after the closing parenthesis of a method argument block

Do not put

CodePudding user response:

In c# we use the semi colon to close our statements. A method is a statement that contains other statements!

public void update(); "<-- Tells the code to run \"public void update\". But it can't access the contents because the method hasn't been fully declared."
    //{
        //if(input.getmousebuttondown(0))
        //{
            //if (canAttack)
            //{
              //swordAttack();
            //} 
        //}
    //}

public void update()
    {
        if(input.getmousebuttondown(0))
        {
            if (canAttack)
            {
              swordAttack(); "<-- This is fine because we already have \"swordAttack()\"declared."
            } 
        }
    }

public void swordAttack()
    {
      canAttack = false;
     animator anim = sword1.getcomponent<animator>();
     anim.settrigger("attack");
    }
    Ienumerator resetattackcooldown()
    {
     yield return new waitforseconds(attackcooldown);
     canAttack = true;
    }
}
  •  Tags:  
  • c#
  • Related