unity make raycast ignore object
Transform targetTransform = null; // target assigned in inspector
RaycastHit[] hits; // returned hits
LayerMask mask = new LayerMask(); // set in inspector - USE LAYER MASK TO FILTER
hits = Physics.RaycastAll(transform.position, transform.forward, mask);
for(int i =0; i < hits.Length; i++){
if( hits[i].transform == targetTransform){
// Look for a specific transform instance
}
// Or get a specific Component
Ship theShipWeHit = hits[i].transform.GetComponent<Ship>();
if( theShipWeHit != null){
// Found something with a specific script, such as Health or whatever
}
// Or get a specific Tag
if(hits[i].transform.gameObject.CompareTag("Tag")){
// Found something with a given tag.
}
}