Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class RoketLauncher : MonoBehaviour
  6. {
  7. public GameObject rocket;
  8. public GameObject explosion;
  9. public GameObject spawnPoint;
  10. public GameObject player;
  11.  
  12. public AudioClip shotSound;
  13. public AudioClip reloadSound;
  14. public AudioClip emptyGunSound;
  15. public AudioClip explosionSound;
  16.  
  17. public float rocketForce;
  18. public float explosionRadius;
  19. public float explosionDamage;
  20. public LayerMask explosionLayerMask;
  21.  
  22. public int rocketsAmount;
  23.  
  24. int rocketsLeft;
  25. AudioSource source;
  26.  
  27. bool isShot;
  28.  
  29. private void Awake()
  30. {
  31. source = GetComponent<AudioSource>();
  32. rocketsLeft = rocketsAmount;
  33. }
  34.  
  35. private void Update()
  36. {
  37. if (Input.GetButton("Fire1") && rocketsLeft > 0 && isShot!=true)
  38. {
  39. isShot = true;
  40. rocketsLeft -= 1;
  41. source.PlayOneShot(shotSound);
  42. GameObject rocketInstantiated = (GameObject)Instantiate(rocket, spawnPoint.transform.position, player.transform.rotation);
  43. rocketInstantiated.GetComponent<Rocket>().dmg = explosionDamage;
  44. rocketInstantiated.GetComponent<Rocket>().radius = explosionRadius;
  45. rocketInstantiated.GetComponent<Rocket>().explosionSound = explosionSound;
  46. rocketInstantiated.GetComponent<Rocket>().LayerMask = explosionLayerMask;
  47. rocketInstantiated.GetComponent<Rocket>().explosion = explosion;
  48. Rigidbody rocketRb = rocketInstantiated.GetComponent<Rigidbody>();
  49. rocketRb.AddForce(Camera.main.transform.forward * rocketForce, ForceMode.Impulse);
  50. StartCoroutine("Czekaj");
  51. }
  52. }
  53.  
  54. IEnumerator Czekaj()
  55. {
  56. yield return new WaitForSeconds(2.5f);
  57. isShot = false;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement