i have a raycast that shoots too fast i need to incorporate a firerate into it. i am a noob and i have spent an hour trying to fuse them together. if anyone could fuse them and help me out i would really appreciate it.
#pragma strict
var Effect : Transform;
var TheDammage = 100;
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButton(0))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
I NEED TO HAVE THIS INCORPORATED INTO IT
var timeSinceLastShot : float = 0f;
var timeBetweenShots : float = 1 / (shots per second);
void Update() {
timeSinceLastShot += Time.deltaTime;
if(timeSinceLastShot >= timeBetweenShots) {
shoot();
timeSinceLastShot = 0f;
}
}