TeHArGiS10

Untitled

Aug 10th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Shooting : MonoBehaviour {
  5.  
  6. //All
  7. public GameObject laserBeam;
  8. public float shootingForce;
  9. public bool inDelay;
  10. public float shootingDelay = 1f;
  11. public GameObject mainUFO;
  12.  
  13. //Arrays
  14. public GameObject[] healthObjects;
  15. public int[] healthCounts;
  16. public GameObject[] enemyUfos;
  17.  
  18. //Components
  19. Rigidbody rb;
  20. RaycastHit hit;
  21. AudioSource audioSource;
  22.  
  23. //Array 0 = Mave
  24. //Array 1 = MillenniumFalcon
  25.  
  26. void Start ()
  27. {
  28. inDelay = false;
  29. audioSource = GetComponent<AudioSource>();
  30. healthCounts[0] = 100;
  31. healthCounts[1] = 100;
  32. }
  33.  
  34. void Update ()
  35. {
  36. healthObjects[0].transform.rotation = Quaternion.LookRotation(healthObjects[0].transform.position - mainUFO.transform.position);
  37.  
  38. if (Input.GetMouseButton(0))
  39. {
  40. if (!inDelay)
  41. {
  42. StartCoroutine(newShooting());
  43. if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
  44. {
  45. if (hit.transform.tag == "Mave")
  46. {
  47. healthCounts[0] -= 10;
  48. healthObjects[0].GetComponent<TextMesh>().text = healthCounts[0].ToString();
  49.  
  50. if (healthCounts[0] <= 0)
  51. {
  52. Object.Destroy(enemyUfos[0]);
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. IEnumerator newShooting ()
  61. {
  62. GameObject newLaserBeam = Instantiate(laserBeam, new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.rotation) as GameObject;
  63. newLaserBeam.transform.Translate(Vector3.forward * Time.deltaTime, Space.World);
  64.  
  65. rb = newLaserBeam.GetComponent<Rigidbody>();
  66. rb.AddForce(transform.forward * shootingForce);
  67.  
  68. audioSource.Play();
  69.  
  70. inDelay = true;
  71. yield return new WaitForSeconds(shootingDelay);
  72. inDelay = false;
  73.  
  74. yield return new WaitForSeconds(2);
  75. Object.Destroy(newLaserBeam);
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment