so essentially i have code to detect a collision and then if its tag is equal too a building then it goes to that building only problem being that some buildings have box colliders that i use for radiuses to collect resources and it seems whenever it detects this radius then it just ignores the soon collision with the actual building here is my code unsure of what is wrong with it thanks for the help!!!`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Colliderai : MonoBehaviour
{
public float lookRadius = 10f;
NavMeshAgent agent;
public Transform target;
public GameObject radiussawmill;
public GameObject radiusquarry;
public GameObject radiusoilrig;
public void OnCollisionEnter(Collision collision)
{
print("touch");
if (collision.gameObject.name == "prefabsawmill" )
{
target = collision.gameObject.transform;
Target();
}
else
{
Physics.IgnoreCollision(radiussawmill.GetComponent<Collider>(), GetComponent<Collider>());
}
}
private void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
void Target ()
{
float distance = Vector3.Distance(target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination(target.position);
if (distance <= agent.stoppingDistance)
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 20f);
}
}
}
}`