Advertisement
Diamond32_Tutoriales

WeaponWithFireRate

Aug 16th, 2023
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ScarController : MonoBehaviour
  6. {
  7. public float MinDamageMount = 5;
  8. public float MaxDamageMount = 10;
  9. public float FireRate = 1f;
  10. public float ShootDistance = 100;
  11. float nextRate;
  12. public Transform Camera;
  13. public LayerMask mask;
  14. public PlayerController plr;
  15. public CharacterController controller;
  16. public Animator anim;
  17. public GameObject impactFX;
  18.  
  19. void Update()
  20. {
  21. RaycastHit hit;
  22.  
  23. if (Input.GetKey (KeyCode.Mouse0))
  24. {
  25. if (Time.time >= nextRate)
  26. {
  27. nextRate = Time.time + 1 / FireRate;
  28. #if UNITY_EDITOR
  29. Debug.Log ("DISPARANDO");
  30. #endif
  31.  
  32. if (Physics.Raycast (Camera.transform.position, Camera.transform.forward, out hit, ShootDistance, mask))
  33. {
  34. if (hit.collider != null)
  35. {
  36. GameObject fx = Instantiate (impactFX);
  37. fx.transform.position = hit.point;
  38.  
  39. Destroy (fx, 3f);
  40. }
  41. }
  42. }
  43. }
  44.  
  45.  
  46.  
  47. if (controller.velocity.magnitude != 0)
  48. {
  49. anim.SetBool ("Walk", false);
  50. anim.SetBool ("Walk", true);
  51.  
  52. if (plr.isRunning)
  53. {
  54. anim.SetBool("Run", false);
  55. anim.SetBool("Run", true);
  56. }
  57. else
  58. {
  59. anim.SetBool("Run", true);
  60. anim.SetBool("Run", false);
  61. }
  62. }
  63. else
  64. {
  65. anim.SetBool("Run", true);
  66. anim.SetBool("Run", false);
  67. anim.SetBool("Walk", true);
  68. anim.SetBool("Walk", false);
  69. }
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement