#Issue with enemy fire
1 messages · Page 1 of 1 (latest)
Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
done, anything else?
Where's the code?
public float minFireDelay = 0.5f;
public float maxFireDelay = 1.5f;
private float nextFireTime;
void Start()
{
Debug.Log(gameObject.name + " EnemyShoot STARTED");
if (bulletPrefab == null)
{
Debug.LogError("Bullet Prefab NOT assigned on " + gameObject.name);
}
if (firePoint == null)
{
Debug.LogError("FirePoint NOT assigned on " + gameObject.name);
}
nextFireTime = Time.time + Random.Range(minFireDelay, maxFireDelay);
Debug.Log(gameObject.name + " first shot scheduled at: " + nextFireTime);
}
void Update()
{
if (Time.time >= nextFireTime)
{
Debug.Log(gameObject.name + " FIRED at time: " + Time.time);
Shoot();
nextFireTime = Time.time + Random.Range(minFireDelay, maxFireDelay);
Debug.Log(gameObject.name + " next shot scheduled at: " + nextFireTime);
}
}
void Shoot()
{
if (bulletPrefab == null || firePoint == null)
{
Debug.LogError("Cannot shoot — missing references on " + gameObject.name);
return;
}
Instantiate(bulletPrefab, firePoint.position, Quaternion.identity);
}
}
theres my enemy shoot code
You should keep the console window visible at all times
If this has yet to be resolved, the issue should be in your inspector. The value of maxFireDelay is set to 0 on your EnemyShoot script