I need help on getting rid of that error here is my code
The Gun code
using UnityEngine;
public class Gun : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public Camera MainCamera;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown(“Fire1”))
{
Shoot();
}
}
void Shoot()
{
RaycastHit hit;
if (Physics.Raycast(MainCamera.transform.position, MainCamera.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent();
if (target != null) ;
{
target.TakeDamage(damage);
}
}
}
}
The Target code
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 50f;
public void TakeDamage (float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}