BRACKEYS raycast shooting issue

Im new to unity and im following brackeys tutorial on shooting with raycast and ive ran into an issue with the crate not being destroyed after 5shots. I really need this solved because breaking the objects and shattering objects will be an extreme feature in my game. I dont know what script is the problem.

Target script:

using UnityEngine;

public class Target : MonoBehaviour
{
public float health = 50f;

public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}

void Die()
{
Destroy(gameObject);
}
}

Gun script

using UnityEngine;

public class GUN : MonoBehaviour {

public float damage = 10f;
public float range = 100f;

public Camera fpsCam;

// Update is called once per frame
void Update () {

if (Input.GetButtonDown(“Fire1”))
{
Shoot();
}

}

void Shoot ()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);

Target target = hit.transform.GetComponent();
if (target != null)
{
target.TakeDamage(damage);
}
}
}
}

Sprinkle Debug.Log statements around your code to see what’s going wrong. Put one inside the TakeDamage method to make sure it’s being called and the health values are what you expect. Is the Debug.Log inside your Raycast if statement printing out properly?

Hi, i am seeing the below which would mean the crate is being hit?

Wooden_Crate (1)
UnityEngine.Debug:Log(Object)
Gun:shoot() (at Assets/GUNSCRIPT.cs:26)
Gun:Update() (at Assets/GUNSCRIPT.cs:15)

I’ll add somemore Debug.Log’s

it would seem your crate is being hit yes. Is the TakeDamage method then being called? Maybe there’s not actually a “Target” component on the crate? Adding more logs to figure these things out is the key.

Ok, i’m not sure how to add the Debugs, can you provide some examples ? Very new to this !

are u still there?

Hi, everyone i just want to say “THE PROBLEM IS SOLVED!!!” thank u for the help