Qu/Assets/Scripts/Shoot.cs
Gerard Gascón bd5b1556ff init
2025-04-24 14:23:29 +02:00

26 lines
669 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour{
public float timeBetweenShots;
public Transform firePoint;
public GameObject bullet;
float lastTimeShot;
float shotCounter;
public void Fire(){
if (Time.time > lastTimeShot + timeBetweenShots){
shotCounter -= Time.deltaTime;
if (shotCounter <= 0){
lastTimeShot = Time.time;
shotCounter = timeBetweenShots;
Instantiate(bullet, firePoint.position, firePoint.rotation);
}
}else{
shotCounter = 0;
}
}
}