Hey guys. Got myself a nice working raycasting “shooting” script.
public bool firing = false;
public float fireRate = 0.1f;
if(Input.GetButtonDown("Fire1"))
{
if(canShoot == true)
{
Screen.lockCursor = true;
Ray mouseRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hitInfo;
if(Physics.Raycast(mouseRay, out hitInfo))
{
Debug.Log(hitInfo.transform.name);
curAmmoInClip -= 1;
Health enemyHealth = hitInfo.transform.GetComponent<Health>();
if(enemyHealth !=null)
{
enemyHealth.Damage(damage);
}
}
}
}
Basically I would like to know how I could set up a “fire rate”, so that the raycasts only shoot out when it is allowed to due to the fire rate. I know it’s something to do with time.deltatime, but i can’t work out how quite to do it, or where i would even add it in my gun script.
I guess another way to describe it would be a timed delay of when the rays can get sent out… I’m not too sure how to word it
I hope that makes sense?
thanks in advanced
BONUS help
(Isn’t as important as the above bit as i have not got round to researching this bit yet, but if your willing to help and point me in the right direction, i’m not going to complain xD)
I’m not too sure how i would go about adding sound to each “ray” that is cast out or even to instantiate a prefab / texture where the ray lands, or instantiate a different one depending on the layer the raycast has hit… But i’ll do some more research on this before i ask for help