Almost Final Version
This commit is contained in:
@ -1,47 +1,46 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shooting : MonoBehaviour
|
||||
{
|
||||
public float damage = 10f;
|
||||
public float range = 100f;
|
||||
|
||||
public GameObject raycast;
|
||||
|
||||
public GameObject FirePoint;
|
||||
public GameObject[] Prefabs;
|
||||
public GameObject firePoint;
|
||||
[SerializeField] private GameObject projectilePrefab;
|
||||
|
||||
private float hSliderValue = 0.1f;
|
||||
private float fireCountdown = 0f;
|
||||
|
||||
private int Prefab = 1;
|
||||
|
||||
private Ray RayMouse;
|
||||
private Vector3 direction;
|
||||
private Quaternion rotation;
|
||||
private float _fireCountdown = 1f;
|
||||
|
||||
public GameObject gun;
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButton(0) && fireCountdown <= 0f)
|
||||
{
|
||||
Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation);
|
||||
fireCountdown = 0;
|
||||
fireCountdown += hSliderValue;
|
||||
Shoot();
|
||||
}
|
||||
fireCountdown -= Time.deltaTime;
|
||||
HandleMouseButton();
|
||||
}
|
||||
|
||||
private void HandleMouseButton()
|
||||
{
|
||||
if (Input.GetMouseButton(0) && _fireCountdown <= 0f)
|
||||
{
|
||||
_fireCountdown = 0;
|
||||
_fireCountdown += hSliderValue;
|
||||
Shoot();
|
||||
}
|
||||
_fireCountdown -= Time.deltaTime;
|
||||
}
|
||||
|
||||
public void Shoot()
|
||||
{
|
||||
if (Physics.Raycast(raycast.transform.position, raycast.transform.forward, out var hit, range))
|
||||
if (Physics.Raycast(raycast.transform.position,
|
||||
raycast.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
Debug.Log(hit.transform.name);
|
||||
|
||||
if (hit.transform.TryGetComponent<Target>(out var target))
|
||||
target.TakeDamage(damage);
|
||||
if (hit.transform.TryGetComponent<NPC>(out var target))
|
||||
{
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user