Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum shootType
- {
- Semi_automatica,
- Automatica,
- Manual
- };
- public class WeaponsShoot : MonoBehaviour
- {
- [Header("Configuracion General || Manual || Automatica")]
- public float Daño;
- public float RangoDeDisparo;
- public Camera cam;
- RaycastHit hit;
- public LayerMask MascarasPermitidas;
- public GameObject muzzleFlash;
- public GameObject ImpactFX;
- float siguientetiempodedisparo;
- public shootType TipoDeArma;
- public AudioSource sm;
- public AudioClip SonidoDeDisparo;
- [Header("Configuracion Semi Automatica")]
- public int DisparosPosClick;
- public float DañoPorDisparo;
- [Range(0, 1)] public float TiempoDeBala;
- [Header("Configuracion Automatica")]
- [Range(0, 200)] public float FireRate;
- public bool isShooting;
- [Header("Configuracion Manual")]
- public float dañoManual;
- public PlayerController controller;
- void Start()
- {
- }
- void Update()
- {
- switch (TipoDeArma)
- {
- case shootType.Automatica:
- {
- if (Input.GetKey(KeyCode.Mouse0) && !isShooting)
- {
- StartCoroutine(shootgin());
- isShooting = true;
- }
- break;
- }
- case shootType.Semi_automatica:
- {
- if (Input.GetKeyDown(KeyCode.Mouse0) && !isShooting)
- {
- StartCoroutine(semiAutomatica());
- isShooting = true;
- }
- break;
- }
- case shootType.Manual:
- {
- if (Input.GetKeyDown(KeyCode.Mouse0) && !isShooting)
- {
- StartCoroutine(shootgin());
- isShooting = true;
- }
- break;
- }
- }
- }
- IEnumerator semiAutomatica()
- {
- int i;
- for ( i = 0; i < DisparosPosClick; i++)
- {
- StartCoroutine(semiAutomaticaShoot());
- yield return new WaitForSeconds (TiempoDeBala);
- }
- isShooting = false;
- i = 0;
- }
- IEnumerator shootgin()
- {
- yield return new WaitForSeconds(1 / FireRate);
- if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, RangoDeDisparo, MascarasPermitidas))
- {
- if (hit.collider.GetComponent<FollowPlayer>())
- {
- FollowPlayer fl = hit.collider.GetComponent<FollowPlayer>();
- fl.lifeRemove(DañoPorDisparo);
- }
- GameObject muzle = Instantiate(ImpactFX, hit.point, Quaternion.LookRotation(hit.normal), null);
- Destroy(muzle, 1f);
- }
- sm.PlayOneShot(SonidoDeDisparo, 0.5f);
- isShooting = false;
- }
- IEnumerator semiAutomaticaShoot()
- {
- yield return new WaitForSeconds(1 / FireRate);
- if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, RangoDeDisparo, MascarasPermitidas))
- {
- if (hit.collider.GetComponent<FollowPlayer>())
- {
- FollowPlayer fl = hit.collider.GetComponent<FollowPlayer>();
- fl.lifeRemove(DañoPorDisparo);
- }
- GameObject muzle = Instantiate(ImpactFX, hit.point, Quaternion.LookRotation(hit.normal), null);
- Destroy(muzle, 1f);
- }
- sm.PlayOneShot(SonidoDeDisparo, 0.5f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement