Made enemies shoot

This commit is contained in:
Pasha Bibko
2026-01-29 11:52:12 +00:00
parent ab67608192
commit 42113c9ff5
3 changed files with 318 additions and 0 deletions

View File

@@ -11,10 +11,14 @@ namespace InterfaceOff.WorldScene
[SerializeField] private Rigidbody Body;
[SerializeField] private GameObject RendererObject;
[SerializeField] private GameObject ExplosionPrefab;
[SerializeField] private LineRenderer BulletTracer;
[SerializeField] private GameObject GunStart;
[SerializeField] private GameObject Head;
private Quaternion StartRotation;
private Vector3 StartPosition;
private bool StartedShooting;
private bool WasAliveLastFrame;
private bool Alive = true;
@@ -31,6 +35,13 @@ namespace InterfaceOff.WorldScene
/* Updates the death state */
WasAliveLastFrame = Alive;
Alive = DeathIndex >= Player.FrameIndex;
/* Checks if it is about to die or kill */
if (DeathIndex == (Player.FrameIndex + 10) && !StartedShooting)
{
StartCoroutine(routine: ShootyShooty());
StartedShooting = true;
}
/* Checks if it just died */
if (!Alive && WasAliveLastFrame)
@@ -50,6 +61,28 @@ namespace InterfaceOff.WorldScene
RendererObject.SetActive(true);
Body.Sleep();
}
/* Check for resurrection */
if (Alive && !WasAliveLastFrame)
{
StartedShooting = false;
}
}
private IEnumerator ShootyShooty()
{
BulletTracer.enabled = true;
for (int i = 0; i < 10; i++)
{
BulletTracer.SetPosition(0, Head.transform.position);
BulletTracer.SetPosition(1, Player.transform.position);
BulletTracer.SetPosition(2, GunStart.transform.position);
yield return new WaitForFixedUpdate();
}
BulletTracer.enabled = false;
}
private IEnumerator Suicide()