51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class Shooting : MonoBehaviour
|
|
{
|
|
public GameObject raycast;
|
|
|
|
public GameObject firePoint;
|
|
//[SerializeField] private ParticleSystem projectilePrefab;
|
|
public ParticleSystem projectilePrefab;
|
|
|
|
private float hSliderValue = 0.1f;
|
|
private float _fireCountdown = 1f;
|
|
|
|
public GameObject gun;
|
|
public AudioSource audioSource;
|
|
|
|
private void Update()
|
|
{
|
|
HandleMouseButton();
|
|
}
|
|
|
|
private void HandleMouseButton()
|
|
{
|
|
if (Input.GetMouseButton(0) && _fireCountdown <= 0f)
|
|
{
|
|
_fireCountdown = 0;
|
|
_fireCountdown += hSliderValue;
|
|
audioSource.Play();
|
|
Instantiate(projectilePrefab, gun.transform.position, gun.transform.rotation);
|
|
Shoot();
|
|
}
|
|
_fireCountdown -= Time.deltaTime;
|
|
}
|
|
|
|
public void Shoot()
|
|
{
|
|
if (Physics.Raycast(raycast.transform.position,
|
|
raycast.transform.forward, out var hit,
|
|
SettingsReader.Instance.GetSettings.ViewDistance))
|
|
{
|
|
if (hit.transform.TryGetComponent<NPC>(out var target))
|
|
{
|
|
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
|
}
|
|
}
|
|
}
|
|
}
|