Hi, I currently have a RayCast that acts more of a combat rifle/pistol. It shoots once per click. How do I transform my script to make it into a machine gun script where I don’t have to click once, but instead hold the button for continuous fire?
public class Shooter : MonoBehaviour
{
void Update ( )
{
// 1. Wait for a mouse click.
if ( Input.GetButtonDown( "Fire1" ) )
{
Shoot( );
}
}
void Shoot ( )
{
// 2. Create a ray that travels from your camera
// in the direction it's facing.
Ray ray = new Ray( transform.position, transform.forward );
RaycastHit hit;
if ( Physics.Raycast( ray, out hit ) )
{
// 3. Check the first thing it hits, is it your enemy?
// If so (actually there is nothing defined as enemy);
hit.transform.SendMessage( "OnBullet",
SendMessageOptions.DontRequireReceiver );
}
}