error CS0106

the error is: Assets\damage.cs(17,2): error CS0106: The modifier ‘public’ is not valid for this item
pls help

here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class damage : MonoBehaviour{

    public int health;
   
    public GameObject bloodEffect;
   
    void Update(){
       
        if(health <= 0){
            Destroy(gameObject);
        }
       
    public void TakeDamage(int damage){
        instantiate(bloodEffect, transform.position, quaternion.identity);
        health -= damage;
        Debug.Log("damage TAKEN !");
        }
    }
}

Your TakeDamage method is inside you Update method.
Move it out of there and it will work.

1 Like

Also, please note that this isn’t a 2D question, it’s a scripting question so is best posted on the scripting forum here.