using UnityEngine;

public class PlayerShoot : MonoBehaviour {

    public float damage = 10f;
    public float range = 100f;

    public Camera camera;
    
    private void Update() {
        if (Input.GetButtonDown("Fire1")) {
            RaycastHit hit;
            if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, range)) {
                Target target = hit.transform.GetComponent<Target>();
                if (target != null) {
                    target.takeDamage(damage, transform);
                }
            }
        }
    }
}