2021-01-05 13:10:20 +01:00
|
|
|
using System;
|
2021-01-11 13:42:43 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using FMOD;
|
2021-01-05 13:10:20 +01:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
2021-01-11 13:42:43 +01:00
|
|
|
using Debug = UnityEngine.Debug;
|
2021-01-05 13:10:20 +01:00
|
|
|
using PlayerInput = Input.PlayerInput;
|
|
|
|
public class PlayerShootInput : ShootInputBase
|
|
|
|
{
|
|
|
|
private PlayerInput _actions;
|
|
|
|
|
|
|
|
private bool _isShooting;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
_actions = new PlayerInput();
|
|
|
|
}
|
2021-01-11 13:42:43 +01:00
|
|
|
|
2021-01-05 13:10:20 +01:00
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
_actions.Enable();
|
|
|
|
_actions.Default.Shoot.performed += Shoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
_actions.Disable();
|
|
|
|
_actions.Default.Shoot.performed -= Shoot;
|
|
|
|
}
|
|
|
|
|
2021-01-11 13:42:43 +01:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
StartCoroutine(MakePewSounds());
|
|
|
|
}
|
|
|
|
|
2021-01-05 13:10:20 +01:00
|
|
|
private void Shoot(InputAction.CallbackContext obj)
|
|
|
|
{
|
|
|
|
_isShooting = obj.ReadValueAsButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsShooting()
|
|
|
|
{
|
|
|
|
return _isShooting;
|
|
|
|
}
|
|
|
|
|
2021-01-11 13:42:43 +01:00
|
|
|
private IEnumerator MakePewSounds()
|
|
|
|
{
|
|
|
|
var wait = new WaitForSeconds(0.02f);
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (_isShooting)
|
|
|
|
{
|
|
|
|
FMODUnity.RuntimeManager.PlayOneShot("event:/shoot");
|
|
|
|
}
|
|
|
|
|
|
|
|
yield return wait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 13:10:20 +01:00
|
|
|
}
|