Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using RootMotion.Dynamics;
- using RootMotion.FinalIK;
- using StarterAssets;
- using TMPro;
- public class AssaultRifle : MonoBehaviour
- {
- // Start is called before the first frame update
- public StarterAssetsInputs starterAssetsInputs;
- public GameObject Bullet;
- public GameObject MuzzleFlash;
- public Transform firePoint;
- public GameObject player;
- float timetofire = 0;
- public float firerate;
- public float recoilMagnitude = 1f;
- public AudioClip shootSound;
- public AudioSource s1;
- private Recoil recoil;
- void Start()
- {
- Cursor.lockState = CursorLockMode.Locked;
- Cursor.visible = false;
- recoil = player.GetComponent<Recoil>();
- }
- void Update()
- {
- if (starterAssetsInputs.select && Time.time > timetofire)
- {
- shooting = true;
- Instantiate(MuzzleFlash, firePoint.position, firePoint.rotation);
- Shoot();
- GetComponent<soundManager>().PlaySound();
- recoil.Fire(recoilMagnitude);
- timetofire = Time.time + 1 / firerate;
- }
- }
- void Shoot()
- {
- GameObject BulletNew = Instantiate(Bullet, firePoint.position, firePoint.rotation);
- BulletNew.GetComponent<Bullet>().sender = gameObject.transform.root.gameObject;
- Destroy(BulletNew, 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment