TeHArGiS10

Untitled

Aug 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Shooting : MonoBehaviour {
  5.  
  6. public GameObject laserBeam;
  7. public float shootingForce;
  8. public bool inDelay;
  9. public float shootingDelay = 1f;
  10. Rigidbody rb;
  11.  
  12. void Start ()
  13. {
  14. inDelay = false;
  15. StartCoroutine(newShooting());
  16. }
  17.  
  18. void Update ()
  19. {
  20. if (Input.GetMouseButtonDown(0))
  21. {
  22. if (!inDelay)
  23. {
  24. newShooting();
  25. }
  26. }
  27. }
  28.  
  29. IEnumerator newShooting ()
  30. {
  31. GameObject newLaserBeam = Instantiate(laserBeam, new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.rotation) as GameObject;
  32. newLaserBeam.transform.Translate(Vector3.forward * Time.deltaTime, Space.World);
  33.  
  34. rb = newLaserBeam.GetComponent<Rigidbody>();
  35. rb.AddForce(transform.forward * shootingForce);
  36.  
  37. inDelay = true;
  38. yield return new WaitForSeconds(shootingDelay);
  39. inDelay = false;
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment