I have a bullet script that fires and damages the enemy which is this
using UnityEngine;
using System.Collections;
public class Gunhit
{
public float damage;
public RaycastHit hitInfo;
}
public class bullet : MonoBehaviour {
public float delay=0.1f;
public float damage = 1.0f;
private bool readyTofire = true;
public AudioSource gunshot;
public ParticleSystem muzzleFlash;
public float ammoCount = 30f;
// Update is called once per frame
void Update () {
gunshot.GetComponent<AudioSource>();
muzzleFlash.GetComponent<ParticleSystem>();
muzzleFlash.enableEmission = false;
if(Input.GetMouseButtonDown(0)&& readyTofire&&ammoCount!=0)
{
gunshot.Play();
muzzleFlash.enableEmission = true;
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if (Physics.Raycast(ray, out hit))
{
hit.transform.SendMessage("OnBullet",
SendMessageOptions.DontRequireReceiver);
ammoCount--;
}
}
}
}
and an ammo script
public class ammo : MonoBehaviour {
public GameObject Shoot;
public void onTriggerEnter(Collider collision)
{
if(collision.tag=="ammo")
{
Shoot.GetComponent<bullet>().ammoCount += 10;
Destroy(collision.gameObject);
}
}
}
but when I collide with the object tagged ammo nothing happens can someone tell me what I am doing wrong.