Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Photon.Pun;
- using Sirenix.OdinInspector;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.Rendering;
- public class CanFireBullets : ArenaObject
- {
- [FoldoutGroup("Additional Properties"), PropertyOrder(4)]
- [Tooltip("Prefab used as the bullet."), AssetsOnly, AssetSelector(Paths = "Assets/Resources")]
- public GameObject _bulletPrefab;
- [FoldoutGroup("Additional Properties"), PropertyOrder(4)]
- [Required("Spawning transform required to spawn bullet!", InfoMessageType.Info), ChildGameObjectsOnly]
- public Transform spawningTransform;
- [FoldoutGroup("Additional Properties"), PropertyOrder(4)]
- public float flareIntensity;
- [BoxGroup("Clip")]
- public GunClip clip;
- internal IEnumerator _startReloading;
- [BoxGroup("Rotation/Aiming")]
- public GunRotation gunRotation;
- public BulletProperties bulletProperties;
- [HideInInspector]
- public ShootFlare _shootFlare;
- [FoldoutGroup("UnityEvents"), PropertyOrder(-1)]
- public UnityEvent onBulletFire;
- private bool _syncLock;
- #region Start/Update
- void Start()
- {
- bulletProperties.launchParameters.spawnTransform = spawningTransform;
- _shootFlare.barrelFlare = GetComponentInChildren<LensFlareComponentSRP>();
- }
- void Update()
- {
- _shootFlare.UpdateFlare();
- }
- #endregion
- [Button("Shoot Gun"), FoldoutGroup("Function Calls"), DisableInEditorMode, PropertyOrder(0), Tooltip("Title kind of gives it away, don'it?")]
- public void FireOnce()
- {
- if (_syncLock || clip._ammoCurrent <= 0) return;
- _syncLock = true;
- photonView.RPC(nameof(Network_SingleShot), RpcTarget.All);
- }
- // todo StartShooting / StopShooting
- [PunRPC]
- private void Network_SingleShot()
- {
- _syncLock = false;
- var launchParameters = bulletProperties.launchParameters;
- var damageUnit = bulletProperties.damageUnit;
- SpawnBullet(launchParameters, damageUnit);
- _shootFlare.ShowFlare(flareIntensity);
- clip.ReduceClip(1);
- _startReloading = clip.IsReloading();
- StartCoroutine(_startReloading);
- onBulletFire.Invoke();
- }
- private void SpawnBullet(BulletProperties.LaunchParameters launch, BulletProperties.DamageUnit damage)
- {
- var newBullet = Instantiate(_bulletPrefab, spawningTransform.position, spawningTransform.transform.rotation);
- newBullet.GetComponent<Rigidbody>().velocity = launch.speed * launch.spawnTransform.transform.forward;
- newBullet.GetComponent<Bullet>().damageUnit = damage;
- }
- }
Add Comment
Please, Sign In to add comment