コード例 #1
0
    void Update()
    {
        Vector3 laserDirection = transform.forward;

        Ray ray = new Ray(transform.position, laserDirection);

        Physics.Raycast(ray,
                        out RaycastHit hitInfo,
                        maxDistance,
                        LayerMask.GetMask("Walls", "Player", "PastPlayer"),
                        QueryTriggerInteraction.Ignore);

        laserLine.SetPosition(0, transform.position);

        if (hitInfo.collider != null)
        {
            laserLine.SetPosition(1, hitInfo.point);

            if (hitInfo.collider.gameObject.layer == LayerMask.NameToLayer("Player"))
            {
                securitySystem.DetectedPresentPlayer();
            }
        }
        else
        {
            laserLine.SetPosition(1, this.transform.position + laserDirection * maxDistance);
        }
    }