Question by
klisman · Jan 07, 2016 at 04:29 PM ·
c#2dinputprogramming
Function runs twice
I have this function that takes an input, for some reason it is happening twice for each input.
if (Input.GetButton ("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
Vector3 offset = transform.rotation * new Vector3 (0, 0.20f, 0);
bullet = (GameObject)Instantiate (bulletPrefab, transform.position + offset, WeaponsScript.weaponsRotation);
bullet.layer = gameObject.layer;
Debug.Log ("Pew");
}
I got 2 debugs "Pew" in console, fireRate = 2f.
Comment
$$anonymous$$ake sure that you have only one of that script attached in scene, can use something like that:
Debug.Log(GameObject.FindObjectsOfType<SCRIPT>().length);