Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RoketLauncher : MonoBehaviour
- {
- public GameObject rocket;
- public GameObject explosion;
- public GameObject spawnPoint;
- public GameObject player;
- public AudioClip shotSound;
- public AudioClip reloadSound;
- public AudioClip emptyGunSound;
- public AudioClip explosionSound;
- public float rocketForce;
- public float explosionRadius;
- public float explosionDamage;
- public LayerMask explosionLayerMask;
- public int rocketsAmount;
- int rocketsLeft;
- AudioSource source;
- bool isShot;
- private void Awake()
- {
- source = GetComponent<AudioSource>();
- rocketsLeft = rocketsAmount;
- }
- private void Update()
- {
- if (Input.GetButton("Fire1") && rocketsLeft > 0 && isShot!=true)
- {
- isShot = true;
- rocketsLeft -= 1;
- source.PlayOneShot(shotSound);
- GameObject rocketInstantiated = (GameObject)Instantiate(rocket, spawnPoint.transform.position, player.transform.rotation);
- rocketInstantiated.GetComponent<Rocket>().dmg = explosionDamage;
- rocketInstantiated.GetComponent<Rocket>().radius = explosionRadius;
- rocketInstantiated.GetComponent<Rocket>().explosionSound = explosionSound;
- rocketInstantiated.GetComponent<Rocket>().LayerMask = explosionLayerMask;
- rocketInstantiated.GetComponent<Rocket>().explosion = explosion;
- Rigidbody rocketRb = rocketInstantiated.GetComponent<Rigidbody>();
- rocketRb.AddForce(Camera.main.transform.forward * rocketForce, ForceMode.Impulse);
- StartCoroutine("Czekaj");
- }
- }
- IEnumerator Czekaj()
- {
- yield return new WaitForSeconds(2.5f);
- isShot = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement