How to call a method with input parameters from script B to script A (script A attached to a Object but B just used to store methods)
Actual problem -- > i have created "AI Behavior" script (Script B). In this script i have created bool method "IsDetected" using Raycast and Ray with a array and foreach loop and on calling this method to Player script (Script A) i am getting return value = "True" on firsst cycle but on second cycle it sending false because of there is null for hit.collider.transform.tag = "Player".
here id code : In Script A we ll just only call this method. Player script B :
public bool IsDetectedTarget(GameObject _rayEmitter, float _scanRange, string _targetTagName) {
Ray[] rayforSearch = new Ray[1];
Vector3 noAngle = _rayEmitter.transform.forward;
Debug.DrawLine(_rayEmitter.transform.position, _rayEmitter.transform.position + noAngle * _scanRange);
rayforSearch[0] = new Ray(_rayEmitter.transform.position, noAngle);
foreach (Ray ray in rayforSearch)
{
RaycastHit hit;
if (Physics.Raycast(ray, out hit, _scanRange))
{
if (hit.collider.transform.tag =_targetTagName) { return true; }
}
}
return false;
}
Comment