コード例 #1
0
    void RaycastSegment(Vector3 start, Vector3 end, Bullet bullet)
    {
        Vector3 direction = end - start;
        float   range     = direction.magnitude;

        ray.origin    = start;
        ray.direction = direction;
        if (Physics.Raycast(ray, out hitInfo, range))
        {
            Debug.DrawLine(ray.origin, hitInfo.point, Color.red, 1.0f);

            target tgt = hitInfo.transform.GetComponent <target>();
            if (tgt != null)
            {
                tgt.damageTake(damage);
            }

            zombieHealth chesttgt = hitInfo.transform.GetComponent <zombieHealth>();
            if (chesttgt != null)
            {
                chesttgt.damageTake(damage);
            }

            hitEffect.transform.position = hitInfo.point;
            hitEffect.transform.forward  = hitInfo.normal;
            hitEffect.Emit(1);

            bullet.tracer.transform.position = hitInfo.point;
            bullet.time = maxLifetime;
        }
        else
        {
            if (bullet.tracer != null)
            {
                bullet.tracer.transform.position = end;
            }
        }
    }