I have a vehicle that I added to the Bootcamp demo, I am trying to output a message to the console when the soldier shoots the vehicle. The vehicle has a standard box collider around it. I tagged the vehicle as “glass” for testing purposes. I try to output Hit to the log under the tag check for glass in the code below but nothing outputs. Any idea on what I am missing?
function CheckRaycastHit()
{
var hit : RaycastHit;
var glassHit : RaycastHit;
var camRay : Ray;
var origin : Vector3;
var glassOrigin : Vector3;
var dir : Vector3;
var glassDir : Vector3;
if(weaponTransformReference == null)
{
camRay = cam.ScreenPointToRay(new Vector3(Screen.width * 0.5, Screen.height * 0.5, 0));
origin = camRay.origin;
dir = camRay.direction;
origin += dir * 0.1;
}
else
{
camRay = cam.ScreenPointToRay(new Vector3(Screen.width * 0.5, Screen.height * 0.5, 0));
origin = weaponTransformReference.position + (weaponTransformReference.right * 0.2);
if(Physics.Raycast(camRay.origin + camRay.direction * 0.1, camRay.direction, hit, fireRange, hitLayer))
{
dir = (hit.point - origin).normalized;
if(hit.collider.tag == "glass")
{
Debug.Log("HIT");
glassOrigin = hit.point + dir * 0.05;
if(Physics.Raycast(glassOrigin, camRay.direction, glassHit, fireRange - hit.distance, hitLayer))
{
glassDir = glassHit.point - glassOrigin;
}
}
}
else
{
dir = weaponTransformReference.forward;
}
}