
It looks like you're new here. If you want to get involved, click one of these buttons!
Hello, everyone! I've been getting into Unity, and still don't really know C#. I have been using the Brackeys tutorial videos for quite some time. As the question states, I am having trouble with a code. I did the code as the video showed and Unity game me an error, "The type or namespace "Target" could not be found (are you missing a using directory or an assembly reference?)". I looked over my code quite thoroughly and couldn't find anything. I am using Unity 2020.1.4f1 Here is my code:
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<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
}
}
}
Answers
The error meant to say that the script that you are trying to get from the raycast hit is not in existence. So maybe you have misspelled the name or something like that
I actually figured it out, one of the scripts my gun script was referencing was called something different.