Hi, I want to make my enemy wait before damaging it again .
But it Keeps Running every frame, and I tried coroutines as well but I seem they have no Effect
what so ever ;
here is my enemy code .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemy : MonoBehaviour
{
public Transform self;
public MovePLayer player;
public Camera camera;
public int range;
public int offSet;
private bool lookingIsAllowed;
public Target target;
public float distance;
public int Damage;
private gun gunComponent;
// Start is called before the first frame update
void Start()
{
range = 10;
lookingIsAllowed = true;
Damage = 5;
}
// Update is called once per frame
void Update()
{
shoot();
float distance = Vector3.Distance(self.position,player.transform.position);
if(distance <= 10)
{
lookAt();
}
if (target.isBeingAttacked && distance <= 50)
{
lookAt();
}
}
void shoot()
{
RaycastHit hit;
if (Physics.Raycast(camera.transform.position,camera.transform.forward,out hit , range))
{
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(Damage);
target.GetComponent<Rigidbody>().AddForce(hit.transform.position.z * 10f, hit.transform.position.y * 10f, hit.transform.position.z * 10f);
}
}
}
void lookAt()
{
self.LookAt(player.transform);
}
}