67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
//#define TEST_DEATH
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class Shoot : MonoBehaviour{
|
|
|
|
public float[] timeBetweenShots;
|
|
public Transform[] firePoint;
|
|
public Transform secondaryFirePoint;
|
|
|
|
PlayerController player;
|
|
float shotCounter;
|
|
|
|
bool shooting;
|
|
|
|
// Start is called before the first frame update
|
|
void Start(){
|
|
player = GetComponent<PlayerController>();
|
|
}
|
|
|
|
public void PlayerShoot(InputAction.CallbackContext state){
|
|
if (state.performed){
|
|
shooting = true;
|
|
#if TEST_DEATH
|
|
FindObjectOfType<HealthBar>().hp = 0f;
|
|
#endif
|
|
}
|
|
if (state.canceled){
|
|
shooting = false;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update(){
|
|
if (shooting && player.gunSelected == 0){
|
|
shotCounter -= Time.deltaTime;
|
|
if (shotCounter <= 0){
|
|
shotCounter = timeBetweenShots[0];
|
|
AudioManager.instance.Play("Shoot");
|
|
ObjectPooler.Instance.SpawnFromPool("Bullet", firePoint[0].position, firePoint[0].rotation);
|
|
player.speed = player.shootingSpeed;
|
|
}
|
|
}else if(shooting && player.gunSelected == 1){
|
|
shotCounter -= Time.deltaTime;
|
|
if (shotCounter <= 0){
|
|
shotCounter = timeBetweenShots[1];
|
|
AudioManager.instance.Play("Shoot");
|
|
ObjectPooler.Instance.SpawnFromPool("BigBullet", firePoint[1].position, firePoint[1].rotation);
|
|
player.speed = player.shootingSpeed;
|
|
}
|
|
}else if(shooting && player.gunSelected == 2){
|
|
shotCounter -= Time.deltaTime;
|
|
if (shotCounter <= 0){
|
|
shotCounter = timeBetweenShots[2];
|
|
AudioManager.instance.Play("Shoot");
|
|
ObjectPooler.Instance.SpawnFromPool("Bullet", firePoint[2].position, firePoint[2].rotation);
|
|
ObjectPooler.Instance.SpawnFromPool("Bullet", secondaryFirePoint.position, secondaryFirePoint.rotation);
|
|
player.speed = player.shootingSpeed;
|
|
}
|
|
}else{
|
|
shotCounter = 0;
|
|
player.speed = player.defaultSpeed;
|
|
}
|
|
}
|
|
}
|