Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Shooting : MonoBehaviour {
- public GameObject laserBeam;
- public float shootingForce;
- public bool inDelay;
- public float shootingDelay = 1f;
- Rigidbody rb;
- void Start ()
- {
- inDelay = false;
- StartCoroutine(newShooting());
- }
- void Update ()
- {
- if (Input.GetMouseButtonDown(0))
- {
- if (!inDelay)
- {
- newShooting();
- }
- }
- }
- IEnumerator newShooting ()
- {
- GameObject newLaserBeam = Instantiate(laserBeam, new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.rotation) as GameObject;
- newLaserBeam.transform.Translate(Vector3.forward * Time.deltaTime, Space.World);
- rb = newLaserBeam.GetComponent<Rigidbody>();
- rb.AddForce(transform.forward * shootingForce);
- inDelay = true;
- yield return new WaitForSeconds(shootingDelay);
- inDelay = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment