60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
//Oliver
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
public class Shoot : MonoBehaviour
|
|
{
|
|
[SerializeField] GameObject bulletPrefab;
|
|
[SerializeField] Transform spawnPointAR;
|
|
[SerializeField] Transform spawnPointPistol;
|
|
[SerializeField] WeaponReload weapon;
|
|
[SerializeField] float fireRate = 0.15f;
|
|
[SerializeField] bool AR = true;
|
|
[SerializeField] bool Pistole = true;
|
|
private float nextShotTime;
|
|
|
|
void Start()
|
|
{
|
|
|
|
if (weapon == null)
|
|
weapon = FindFirstObjectByType<WeaponReload>();
|
|
if (weapon == null)
|
|
weapon = FindFirstObjectByType<WeaponReload>();
|
|
if (weapon == null)
|
|
weapon = FindFirstObjectByType<WeaponReload>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
if ( AR == true && Input.GetKey(KeyCode.Mouse0))
|
|
if (PauseMenu.GameIsPaused) return;
|
|
|
|
if (AR == true && Input.GetKey(KeyCode.Mouse0) && Time.time >= nextShotTime)
|
|
|
|
if (PauseMenu.GameIsPaused) return;
|
|
|
|
if (AR == true && Input.GetKey(KeyCode.Mouse0) && Time.time >= nextShotTime)
|
|
|
|
|
|
if (AR == true && Input.GetKey(KeyCode.Mouse0))
|
|
if (PauseMenu.GameIsPaused) return;
|
|
|
|
if (AR == true && Input.GetKey(KeyCode.Mouse0) && Time.time >= nextShotTime)
|
|
{
|
|
Shot(spawnPointAR);
|
|
nextShotTime = Time.time + fireRate;
|
|
}
|
|
else if (Pistole == true && Input.GetKeyDown(KeyCode.Mouse0))
|
|
{
|
|
Shot(spawnPointPistol);
|
|
}
|
|
}
|
|
public void Shot(Transform spawnPoint)
|
|
{
|
|
if (spawnPoint == null || weapon == null || !weapon.UseAmmo()) return;
|
|
|
|
GameObject bullet = Instantiate(bulletPrefab, spawnPoint.position, spawnPoint.rotation);
|
|
bullet.transform.Rotate(90, 0, 0);
|
|
}
|
|
}
|