I am trying to increase my ammo
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.
Answer by mahdiii · Mar 05, 2016 at 01:56 AM
Be sure you go to onTriggerEnter. check isTrigger on And your player has rigidbody.
Your answer
Follow this Question
Related Questions
[Beginner] AutoResolve Combat based on Level 0 Answers
Hey can someone please help me with my ammobar 1 Answer
How to make a boat move without controling it ? 0 Answers
Avoid changes if I dont changing my position. 1 Answer
Pause Script problems 1 Answer