Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question error CS1519: Invalid token 'void' in class, struct, or interface

Discussion in 'Code Editors & IDEs' started by josephCars, Mar 1, 2023.

  1. josephCars

    josephCars

    Joined:
    Mar 1, 2023
    Posts:
    1
    hello

    i just start learning and i stuck with this error. it suposed to be a struct that has name, damage and method that should say about himself.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic; xvideos
    3. using UnityEngine;


    4. public struct Weapon
    5. {
    6. public string name;
    7. public int damage;
    8. public Weapon(string name, int damage)
    9. {
    10. this.name = name;
    11. this.damage = damage;
    12. }
    13. pubic void PrintWeaponStats()
    14. {
    15. Debug.LogFormat("Weapon {0} - {1} dmg", name, damage);
    16. }
    17. }
    hope for your help, thanks!
     
    Last edited: Mar 4, 2023
  2. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,375
    There is a typo in your code. The word "public" in the method PrintWeaponStats() is misspelled as "pubic". :rolleyes: