Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Shooting : MonoBehaviour {
- //All
- public GameObject laserBeam;
- public float shootingForce;
- public bool inDelay;
- public float shootingDelay = 1f;
- public GameObject mainUFO;
- //Arrays
- public GameObject[] healthObjects;
- public int[] healthCounts;
- public GameObject[] enemyUfos;
- //Components
- Rigidbody rb;
- RaycastHit hit;
- AudioSource audioSource;
- //Array 0 = Mave
- //Array 1 = MillenniumFalcon
- void Start ()
- {
- inDelay = false;
- audioSource = GetComponent<AudioSource>();
- healthCounts[0] = 100;
- healthCounts[1] = 100;
- }
- void Update ()
- {
- healthObjects[0].transform.rotation = Quaternion.LookRotation(healthObjects[0].transform.position - mainUFO.transform.position);
- if (Input.GetMouseButton(0))
- {
- if (!inDelay)
- {
- StartCoroutine(newShooting());
- if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
- {
- if (hit.transform.tag == "Mave")
- {
- healthCounts[0] -= 10;
- healthObjects[0].GetComponent<TextMesh>().text = healthCounts[0].ToString();
- if (healthCounts[0] <= 0)
- {
- Object.Destroy(enemyUfos[0]);
- }
- }
- }
- }
- }
- }
- 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);
- audioSource.Play();
- inDelay = true;
- yield return new WaitForSeconds(shootingDelay);
- inDelay = false;
- yield return new WaitForSeconds(2);
- Object.Destroy(newLaserBeam);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment