I’m trying to change a script to shoot 1 bullet per second on mouse being held. The void update and IEnumerator was added by me , the fire() function is the script…
void Update(){
if (Input.GetMouseButton (0)) {
StartCoroutine (FireShot ());
}
}
IEnumerator FireShot() {
Fire ();
yield return new WaitForSeconds (1);
}
public void Fire()
{
Vector3 mousePoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
transform.up = Vector3.Normalize (mousePoint + Vector3.forward * 10 - transform.position);
if (PlayerPrefs.GetInt ("gold", 200) < _levelGun && _tenlua == false)
popUp.SetActive (true);
else {
if (PlayerPrefs.GetInt ("gold", 200) >= _levelGun && _checkfire && _tenlua == false) {
_ani.Play ("Fire", 0, 0);
AudioControl.Instance.shoot ();
GameObject _bullet = (GameObject)Instantiate (Bullet);
_bullet.transform.position = transform.position + transform.up * 0.5f;
_bullet.GetComponent<BulletControl> ().InitBullet (_levelGun, transform, new Vector2 (mousePoint.x, mousePoint.y));
UiTextSpawmControl.Instance.MinusGold (_levelGun);
}
}
if (_tenlua && _checkfire) {
_tenlua = false;
tenlua.transform.up = Vector3.Normalize (mousePoint + Vector3.forward * 10 - tenlua.transform.position);
_checkfire = false;
LeanTween.move (tenlua, new Vector3 (mousePoint.x, mousePoint.y, 0), 0.2f * (Vector2.Distance (mousePoint, tenlua.transform.position))).setOnComplete (() => {
RaycastHit2D[] fish = Physics2D.CircleCastAll (new Vector3 (tenlua.transform.position.x, tenlua.transform.position.y, 0), 2, Vector3.zero);
AudioControl.Instance.boom ();
for (int i = 0; i < fish.Length; i++) {
if (fish *.collider.tag == "fish")*
_ fish .collider.gameObject.GetComponent ().hitDame (1000, gameObject);_
* }*
GameObject boom = (GameObject)Instantiate (_effboom, tenlua.transform.position + tenlua.transform.up * 0.5f, Quaternion.identity);
* Destroy (boom, 1.5f);*
* tenlua.SetActive (false);*
* GetComponent ().enabled = true;*
* transform.up = Vector3.up;*
* transform.localScale = Vector3.zero;*
* LeanTween.scale (gameObject, new Vector3 (1, 1, 1), 0.5f).setEase (LeanTweenType.easeOutBack).setOnComplete (() => {*
* checkfire = true;
_ });*
* });*
* }*
* }*