'Target' does not contain a definition for 'TakeDamage'

This one has stumped me for a whole day now. I was following a tutorial for shooting as you normally would, but then this happened. my error is: (34,24)
‘Target’ does not contain a definition for ‘TakeDamage’ and no accessible extension method ‘TakeDamage’ accepting a first argument of type ‘Target’ could be found (are you missing a using directive or an assembly reference?)
the tutorial is:

(7:20-7:57) and my code is

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

public class Gun : MonoBehaviour
{
   
    public float damage = 15f;
    public float range = 70f;

    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<Target>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
    }

}
}

and though I am sure that nothing could’ve gone wrong, something did. Can anyone help me here?

To answer your post like I did the last time before it got removed (as this post will), make sure you followed the part 5:50 were he writes the ‘TakeDamage’ script correctly, because you probably haven’t.

Seriously, you don’t need to make posts about this. Go back in the video to figure out where you went wrong.

2 Likes

Do not make any more low effort posts like this. All the information is need in the error, you have been told how to fix it. If you still have trouble contact the author of the tutorial if you are not going put any effort into debugging it yourself.