Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question CS1519 C# Invalid token '{' in class, struct, or interface member declaration

Discussion in 'Scripting' started by syazsyahril, May 21, 2020.

  1. syazsyahril

    syazsyahril

    Joined:
    May 17, 2020
    Posts:
    9
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class HD {
    6.     public int health;
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         DamagePlayer(10);
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         if (health <= 0)
    18.         {
    19.             Debug.Log("The player has died! health" + health);
    20.         }
    21.         else if (health >= 15)
    22.         {
    23.             Debug.Log("You have a lot of life");
    24.         }
    25.     }
    26.     void DamagePlayer(int damage)
    27.     {
    28.         health -= damage;
    29.  
    30.     }
    31. }
    32.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class HD {
    6.     public int health;
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         DamagePlayer(10);
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         if (health <= 0)
    18.         {
    19.             Debug.Log("The player has died! health" + health);
    20.         }
    21.         else if (health >= 15)
    22.         {
    23.             Debug.Log("You have a lot of life");
    24.         }
    25.     }
    26.     void DamagePlayer(int damage)
    27.     {
    28.         health -= damage;
    29.  
    30.     }
    31. }
    32.  
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Remove the extra opening curly brace under the "health" field.
     
  3. syazsyahril

    syazsyahril

    Joined:
    May 17, 2020
    Posts:
    9
    Oh my bad, I appreciate