using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PetAi : MonoBehaviour
{
public bool attacking;
public float meleepetattackrange = 3;
public void Attack()
{
if(!attacking)
{
RaycastHit hit;
if (Physics.Raycast(transform.forward, transform.TransformDirection(Vector3.forward), out hit, meleepetattackrange))
{
if(hit.collider.tag == "Dummy")
{
attacking = true;
}
}
}
}
void OnCollisionStay(Collision collision)
{
{
if(attacking)
{
EnemyHealth enemyHealth = collision.gameObject.GetComponent<EnemyHealth>();
if (enemyHealth != null)
{
enemyHealth.TakeDamage(petdamage);
Debug.Log("petdamage");
attacking = false;
}
}
}
}
}
I’m try to cast a ray when attacking = false so the enemy we’ll check for distant before attacking again but the ray won’t change the bool.