Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [SerializeField] GameObject laserFire;
- [SerializeField] float projectileSpeed = 20f;
- private float projectileFiringPeriod = 0.1f;
- Coroutine firingCoroutine;
- void Update()
- {
- Fire();
- }
- IEnumerator FireContinuously() {
- while (true)
- {
- GameObject laser = Instantiate(laserFire, transform.position, Quaternion.identity) as GameObject;
- laser.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
- yield return new WaitForSeconds(projectileFiringPeriod);
- }
- }
- private void Fire() {
- if (Input.GetButtonDown("Fire1"))
- {
- firingCoroutine = StartCoroutine(FireContinuously());
- }
- if (Input.GetButtonUp("Fire1"))
- {
- StopCoroutine(firingCoroutine);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement