Guest User

GameIssue1

a guest
Apr 22nd, 2022
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using RootMotion.Dynamics;
  5. using RootMotion.FinalIK;
  6. using StarterAssets;
  7. using TMPro;
  8.  
  9. public class AssaultRifle : MonoBehaviour
  10. {
  11. // Start is called before the first frame update
  12. public StarterAssetsInputs starterAssetsInputs;
  13. public GameObject Bullet;
  14. public GameObject MuzzleFlash;
  15. public Transform firePoint;
  16. public GameObject player;
  17.  
  18.  
  19. float timetofire = 0;
  20. public float firerate;
  21. public float recoilMagnitude = 1f;
  22. public AudioClip shootSound;
  23. public AudioSource s1;
  24. private Recoil recoil;
  25.  
  26. void Start()
  27. {
  28.  
  29. Cursor.lockState = CursorLockMode.Locked;
  30. Cursor.visible = false;
  31.  
  32. recoil = player.GetComponent<Recoil>();
  33. }
  34.  
  35.  
  36. void Update()
  37. {
  38. if (starterAssetsInputs.select && Time.time > timetofire)
  39. {
  40. shooting = true;
  41. Instantiate(MuzzleFlash, firePoint.position, firePoint.rotation);
  42. Shoot();
  43. GetComponent<soundManager>().PlaySound();
  44.  
  45. recoil.Fire(recoilMagnitude);
  46. timetofire = Time.time + 1 / firerate;
  47.  
  48.  
  49.  
  50.  
  51. }
  52. }
  53.  
  54. void Shoot()
  55. {
  56.  
  57. GameObject BulletNew = Instantiate(Bullet, firePoint.position, firePoint.rotation);
  58. BulletNew.GetComponent<Bullet>().sender = gameObject.transform.root.gameObject;
  59.  
  60. Destroy(BulletNew, 2);
  61. }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment