- Home /
Question by
Hazsha · May 07, 2020 at 02:09 AM ·
instantiateprogrammingspawncontrolrate
when i Instantiate a bullet i can"t control the spawn rate. when i press mouse button down its spawn unlimited without limit
public Rigidbody BulletPrefab; public Transform SpawnPosition;
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Rigidbody prefab = Instantiate(BulletPrefab, SpawnPosition.position, SpawnPosition.rotation) as Rigidbody;
prefab.AddForce(Vector3.forward* 800);
}
}
Comment
Answer by amaljoy205 · May 07, 2020 at 02:43 AM
Use "Input.GetMouseButtonDown(0)" instead of "Input.GetMouseButton(0)" if you want to instantiate single bullet per click. . https://docs.unity3d.com/ScriptReference/Input.GetMouseButtonDown.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612233522im_/https://answers.unity.com/themes/thub/images/avi.jpg)