41 lines
956 B
C#
41 lines
956 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class PlayerShooting_Laser : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private KeyCode shootingKeyCode = KeyCode.Mouse0;
|
||
|
[SerializeField] private float shootDelay = 1;
|
||
|
private float timer = 0;
|
||
|
public GameObject Starship_LASER_bullet;
|
||
|
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
HandleShooting();
|
||
|
}
|
||
|
|
||
|
private void HandleShooting()
|
||
|
{
|
||
|
timer += Time.deltaTime;
|
||
|
if (Input.GetKey(shootingKeyCode) && timer >= shootDelay)
|
||
|
{
|
||
|
timer = 0;
|
||
|
|
||
|
if (Starship_LASER_bullet != null)
|
||
|
{
|
||
|
GameObject newBullet = Instantiate(Starship_LASER_bullet, transform.position, Quaternion.identity);
|
||
|
newBullet.transform.up = transform.up;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|