2020-12-20 13:37:48 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class PlayerShooting : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Transform firePoint;
|
2021-01-25 22:40:51 +01:00
|
|
|
|
public Transform firePoint2;
|
2020-12-20 13:37:48 +01:00
|
|
|
|
public GameObject bullet;
|
|
|
|
|
private bool isShooting = false;
|
2021-01-13 18:58:14 +01:00
|
|
|
|
public float attackDelay = 1.5f;
|
|
|
|
|
private bool isAttackPressed;
|
2021-01-25 22:40:51 +01:00
|
|
|
|
public bool firesecondbullet = false;
|
2020-12-20 13:37:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2021-01-25 22:40:51 +01:00
|
|
|
|
if (Input.GetButton("Fire1"))
|
2020-12-20 13:37:48 +01:00
|
|
|
|
{
|
2021-01-13 18:58:14 +01:00
|
|
|
|
isAttackPressed= true;
|
2020-12-20 13:37:48 +01:00
|
|
|
|
}
|
2021-01-13 18:58:14 +01:00
|
|
|
|
}
|
2020-12-20 13:37:48 +01:00
|
|
|
|
|
2021-01-13 18:58:14 +01:00
|
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (isAttackPressed)
|
2020-12-20 13:37:48 +01:00
|
|
|
|
{
|
2021-01-13 18:58:14 +01:00
|
|
|
|
isAttackPressed = false;
|
|
|
|
|
|
|
|
|
|
if (isShooting == false)
|
|
|
|
|
{
|
|
|
|
|
isShooting = true;
|
|
|
|
|
Instantiate(bullet, firePoint.position, firePoint.rotation);
|
|
|
|
|
Invoke("AttackComplete", attackDelay);
|
2021-01-25 22:40:51 +01:00
|
|
|
|
if(firesecondbullet == true)
|
|
|
|
|
{
|
|
|
|
|
Instantiate(bullet, firePoint2.position, firePoint2.rotation);
|
|
|
|
|
}
|
2021-01-13 18:58:14 +01:00
|
|
|
|
}
|
2020-12-20 13:37:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-13 18:58:14 +01:00
|
|
|
|
void AttackComplete()
|
|
|
|
|
{
|
|
|
|
|
isShooting = false;
|
|
|
|
|
}
|
2020-12-20 13:37:48 +01:00
|
|
|
|
}
|