ZeroVR/ZeroPacientVR/Assets/Scripts/VR/ExtGunBase.cs

81 lines
2.1 KiB
C#

using System.Collections;
using HurricaneVR.Framework.Components;
using HurricaneVR.Framework.Weapons.Guns;
using UnityEngine;
namespace Zero
{
public class ExtGunBase : HVRGunBase
{
[SerializeField] private bool smokeIsParticles;
private ParticleSystem smokeParticles;
private Coroutine smokeToDisable;
protected override void Awake()
{
base.Awake();
if (smokeIsParticles)
{
smokeParticles = MuzzleSmoke.GetComponent<ParticleSystem>();
}
}
protected override void OnHit(GameObject bullet, RaycastHit hit, Vector3 direction)
{
base.OnHit(bullet, hit, direction);
if (bullet.GetComponent<HVRDamageHandlerBase>())
{
bullet.GetComponent<HVRDamageHandlerBase>().HandleRayCastHit(DamageProvider, hit);
}
}
private void OnDisable()
{
if (smokeIsParticles)
{
MuzzleSmoke.SetActive(false);
}
smokeToDisable = null;
}
public void CallShoot()
{
Shoot();
}
protected override void Smoke()
{
if (smokeIsParticles)
{
var play = !MuzzleSmoke.activeSelf;
MuzzleSmoke.SetActive(true);
smokeParticles.Play();
var main = smokeParticles.main;
main.loop = true;
if (smokeToDisable != null)
{
StopCoroutine(smokeToDisable);
}
smokeToDisable = StartCoroutine(SmokeDisable());
}
else
{
base.Smoke();
}
}
private IEnumerator SmokeDisable()
{
yield return new WaitForSeconds(Cooldown + Cooldown * 0.1f);
var main = smokeParticles.main;
main.loop = false;
yield return new WaitForSeconds(MuzzleSmokeTime);
MuzzleSmoke.SetActive(false);
smokeToDisable = null;
}
}
}