- Home /
The question is answered, right answer was accepted
How do I make my raycast shooting script full auto
I have a shoot script that works well but can't figure out how to make it work with full auto weapons
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class newshoot : MonoBehaviour
{
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 1000f))
{
if (hit.transform != null)
{
if (hit.transform.CompareTag("killable"))
{
PrintName(hit.transform.gameObject);
Destroy(hit.collider.gameObject);
}
}
}
}
}
}
I have tried doing it myself but im just getting different errors
Answer by Kaart · Aug 08, 2020 at 02:39 PM
You are using Input.GetMouseButtonDown, this only resets when the user releases the mouse button and presses it again, therefore it doens't work for automatic fire. Use Input.GetMouseButton (see https://docs.unity3d.com/ScriptReference/Input.GetMouseButton.html) instead and maybe use a timer of some sorts to limit the firerate.
Follow this Question
Related Questions
raycast is pointing in two directions? 1 Answer
Trouble with Raycast shooting 1 Answer
How to Fix a Guns Firing Script so it Doesn't Constantly Fire 3 Answers
Raycasting Collider Problem 0 Answers