var Effect : Transform;
var TheDamage = 50;
var BulletSound : AudioClip;
var Ammo : int;
function Start ()
{
Ammo = 30;
}
function Update ()
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButtonDown(0))
{
{
if (Physics.Raycast (ray, hit, 300))
if (Ammo> 0)
{
Ammo --;
BroadcastMessage("Recoil");
audio.PlayOneShot(BulletSound);
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
function OnGUI()
{
if(Ammo > 0)
{
GUI.Label(Rect(100,0,100,100),Ammo.ToString());
}
if(Ammo == 0)
{
GUI.Label(Rect(100,0,100,100),"No Ammo");
}
}
Also my Player atributes code (for the boxes)
function OnTriggerEnter(other : Collider)
{
if(other.tag == "ammo")
{
shootObject.GetComponent(Raycastshooting).Ammo += 30;
Destroy(other.gameObject);
}
}