- Home /
The type or namespace "Target" could not be found?
I'm getting this error message from this 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);
// This is where the error is
Target target = hit.transform.GetComponent<Target>();
}
}
}
I already made sure i didn't spell Target wrong. I also tried the stuff with moving scripts between folders, but it didn't work. Anyone know some other fix?
Can you show the code for the target class? And can you also make sure that the script is named "Target" in your project?
Answer by WahoPlay · Apr 12, 2020 at 03:17 AM
Restart Visual Studio is only thing i can think of right now.
Your answer
Follow this Question
Related Questions
namespace could not be found 0 Answers
Array Out of Index (When it Really is not??) 1 Answer
What is happening and what does this MEAN!?!?!?!?!?!?!?!? AHHHHH!!!!,WHAT IS HAPPENING?!?! 1 Answer
Too many errors in the IDE (even for a fresh project), but editor doesn't throw any errors! 1 Answer
Error: 'WiiU' does not exist in the namespace `UnityEngine` 0 Answers