fixed player in bot fights and their scaled time features (player not time scaled). Now player can join to fights for justice.
This commit is contained in:
57
Assets/Scripts/Weapons/PlayerShooter.cs
Normal file
57
Assets/Scripts/Weapons/PlayerShooter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Animators.Leonid_Animator.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Weapons
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
[RequireComponent(typeof(InputHandler))]
|
||||
public class PlayerShooter : MonoBehaviour
|
||||
{
|
||||
public GameObject firePoint;
|
||||
|
||||
public ParticleSystem projectilePrefab;
|
||||
|
||||
private float _fireCountdown = 0.5f;
|
||||
|
||||
private AudioSource _audioSource;
|
||||
private InputHandler _inputHandler;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
_inputHandler = GetComponent<InputHandler>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleMouseButton();
|
||||
}
|
||||
|
||||
private void HandleMouseButton()
|
||||
{
|
||||
if (_inputHandler.firePressed && _fireCountdown <= 0f)
|
||||
{
|
||||
_fireCountdown = 0.5f;
|
||||
PlayerShoot();
|
||||
}
|
||||
|
||||
_fireCountdown -= Time.unscaledDeltaTime;
|
||||
}
|
||||
|
||||
private void PlayerShoot()
|
||||
{
|
||||
_audioSource.Play();
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
if (Physics.Raycast(firePoint.transform.position,
|
||||
firePoint.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (hit.transform.TryGetComponent<NPC>(out var target))
|
||||
{
|
||||
print($"did damage to {hit.transform.name}");
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user