Problem with Raycast

Well basically I have a cube which when within a certain range from my first person control, starts shooting bullets. There is a problem with the raycasting used to detect when the bullets hit the player. For some reason the bullets get deleted immediately after instantiation though and I can’t figure why. This is the script of the bullet prefab used to destroy the bullets and change the HP of the player if the bullets hit him.

using UnityEngine;
using System.Collections;

public class deletion : MonoBehaviour {
	
	public int death_counter;
	public int damage;
	
	// Use this for initialization
	void Start () {
	Destroy(gameObject, death_counter);
	}
	
	void Update () {
		
	 Vector3 fwd = transform.TransformDirection(Vector3.forward);
	 RaycastHit hit;

        if (Physics.Raycast(transform.position, fwd, out hit, 0.051f) )
			if (hit.collider.name == "Player") {
			HP health = GameObject.Find("Player").GetComponent<HP>();
			health.curHp = health.curHp - damage;
		}
            Destroy(gameObject);
		
	}
}

Any help would be appreciated!

If you would desk-check your program you would know why your bullets only appear for one frame.

In the first frame after instantiation, they calculate if they hit the player, then they destroy themselves. You will have to make some major adjustments to your bullet logic to make it do what I think you want it to do.

Raycasts are quite instant, they don’t take multiple frames to compute.

Your welcome,
Benproductions1