Hi guys my gun script is showing error that the type or namespace ‘Target’ cannot be found.
Pls help me and tell where i am going wrong.
using UnityEngine;
public class Shhot : MonoBehaviour
{
public Animator anim;
public AudioSource sound;
public AudioSource sound1;
public AudioSource sound3;
public float range = 100f;
public float damage = 10f;
public Camera fpsCam;
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1")){
anim.Play("Fire");
sound1.Play();
shoot();
}
if(Input.GetButtonUp("Fire1")){
anim.Play("Idle");
}
if(Input.GetKeyDown("q")){
anim.Play("Knife Attack 1");
}
if(Input.GetKeyDown("r") ){
anim.Play("Reload Ammo Left");
sound.Play();
}
if(Input.GetKeyDown("e")){
anim.Play("Inspect");
}
if(Input.GetButtonDown("Fire2")){
anim.Play("Aim In");
sound3.Play();
}
if(Input.GetButtonUp("Fire2")){
anim.Play("Aim Out");
sound3.Play();
}
if(Input.GetKeyDown("w") ){
anim.Play("Walk");
}
if(Input.GetKeyUp("w")){
anim.Play("Idle");
}
}
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);
}
}
}
}