The script (In C#):
public class Gun : MonoBehaviour {
public GameObject enemy;
// Use this for initialization
void Start () {
}
public float damage = 100f;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
shoot();
}
}
void shoot()
{
RaycastHit hit;
if (Physics.Raycast(transform.position,transform.forward, out hit))
{
Target targ = GetComponent();
if (enemy != null)
{
Destroy(enemy);
}
}
}
}
Okay, so here is the line of code which is not working:
Target targ = GetComponent();
in which I am trying to create a variable type target as I saw in this video:
https://www.youtube.com/watch?v=THnivyG0Mvo
However, when I tried to do this it tells me the type or namespace "Target" could not be found (are you missing a using directive or an assembly reference?) And I already tried looking for errors on this and some people say this error is caused because the script is named "Target" however, that is not the case for me as this script is labelled as Gun. Could somebody please tell me how I could fix this line of code? (Also the entire script isn't the ideal one, I plan to replace the Destroy(gameObject) with something more suitable if I could find the solution to my problem.
↧