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

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

Discussion in 'Code Editors & IDEs' started by Fried_Cintrus, Apr 19, 2022.

  1. Fried_Cintrus

    Fried_Cintrus

    Joined:
    Apr 19, 2022
    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;
    3. using UnityEngine;
    4.  
    5.  
    6. public struct Weapon
    7. {
    8.     public string name;
    9.     public int damage;
    10.     public Weapon(string name, int damage)
    11.     {
    12.         this.name = name;
    13.         this.damage = damage;
    14.     }
    15.     pubic void PrintWeaponStats()
    16.     {
    17.         Debug.LogFormat("Weapon {0} - {1} dmg", name, damage);
    18.     }
    19. }
    20.  
    hope for your help, thanks!