(Edited question)
Hello everyone! I’m in the process of making a shotgun script where you’re supposed to be able to fire a raycast every 1 or so seconds, and the animation is about that long as well, but I’m not sure how to delay the shooting otherwise you can shoot constantly and with infinite ammunition. I would like to have two shots, and when you shoot two, you have to reload, otherwise you hit ‘r’, and it reloads the gun then as well.
Thanks,
Henry
private var AmmoInGun : int = 2;
var Effect : Transform;
var TheDammage = 100;
var Distance = 50;
var Gun : Transform;
function Update ()
{
if (Input.GetKeyDown(KeyCode.R))
{
Reload();
}
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0));
if(Input.GetMouseButtonDown(0))
{
Shoot();
if (Physics.Raycast(ray, hit, Distance))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
if(AmmoInGun == 0)
{
Reload();
}
}
function Shoot()
{
audio.Play();
Gun.animation.CrossFade("Shoot");
AmmoInGun -= 1;
}
function Reload()
{
Gun.animation.CrossFade("RELOAD");
}