hello friends please help me to complete my ai script . this script is almost complete but its problem is when he find enemy tag and kill enemy he is not try to find next enemy please help i am not professional but you guys are here is my srcript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Aishooting02 : MonoBehaviour
{
public float speed;
public float lineofsite;
public float shootingrange;
public GameObject bullet;
public GameObject bulletparent;
private Transform player; //Player is Enemy or target to follow samaz m aya
// Start is called before the first frame update
public GameObject Muzzelflash;
[Range(0, 5)]
public int Frametoflash;
bool _isflashing = false;
void Start()
{
Muzzelflash.SetActive(false);
player = GameObject.FindGameObjectWithTag("Enemy").transform;
}
void Update()
{
float distancefromplayer = Vector2.Distance(player.position, transform.position);
if (distancefromplayer < lineofsite && distancefromplayer > shootingrange)
{
transform.position = Vector2.MoveTowards(this.transform.position, player.position, speed * Time.deltaTime);
}
else if (distancefromplayer <= shootingrange)
{
Instantiate(bullet, bulletparent.transform.position, Quaternion.identity);
if (!_isflashing)
{
StartCoroutine(doflash());
}
}
}
IEnumerator doflash()
{
Muzzelflash.SetActive(true);
var framflased = 0;
_isflashing = true;
while (framflased <= Frametoflash)
{
framflased++;
yield return null;
}
Muzzelflash.SetActive(false);
_isflashing = false;
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(transform.position, lineofsite);
Gizmos.DrawWireSphere(transform.position, shootingrange);
}
}