Example #1
0
    public void LaserHit(LaserEmittingObject other, RaycastHit hit)
    {
        Vector3 OutDir = Vector3.Reflect((transform.position - other.transform.position).normalized, transform.forward.normalized);

        LaserManager.ManagedLaser Laser = LaserManager.RequestLaser();
        Laser.laser.position = hit.point + LaserOffest;
        Laser.laser.rotation = Quaternion.LookRotation(OutDir, transform.up);
        Laser.Active         = true;
        Ray beam = new Ray(hit.point, OutDir);

        Debug.DrawRay(beam.origin, beam.direction * 100, Color.blue);
        if (Physics.Raycast(beam, out hit, Mathf.Infinity, LayerMask.GetMask("Emitter", "Level", "Receiver", "Mirror")))
        {
            Laser.laser.localScale = new Vector3(1, 1, Vector3.Distance(beam.origin, hit.point));
            ILaserableObject laserableObject = hit.collider.gameObject.GetComponent <ILaserableObject>();
            if (laserableObject != null)
            {
                Debug.Log("Hit laserable object: " + hit.transform.name);
                Debug.DrawLine(beam.origin, hit.point, Color.green);
                laserableObject.LaserHit(this, hit);
            }
            else
            {
                Debug.Log("Hit non-laserable object: " + hit.transform.name);
            }
        }
        else
        {
            Laser.laser.localScale = new Vector3(1, 1, 100);
            Debug.Log("No Hit");
        }
    }
Example #2
0
    //private bool laserActive = false;

    #endregion Variables

    #region Methods
    /// <summary>
    /// Called to fire the initial laser
    /// </summary>
    internal void Fire()
    {
        LaserManager.ManagedLaser Laser = LaserManager.RequestLaser();
        Ray        beam = new Ray(transform.position, transform.forward);
        RaycastHit hit;

        Laser.laser.position = beam.origin + LaserOffest;
        Laser.laser.rotation = Quaternion.LookRotation(beam.direction);
        Laser.Active         = true;
        if (Physics.Raycast(beam, out hit, Mathf.Infinity, LayerMask.GetMask("Emitter", "Level", "Receiver", "Mirror")))
        {
            Laser.laser.localScale = new Vector3(1, 1, Vector3.Distance(beam.origin, hit.point));
            ILaserableObject laserableObject = hit.collider.gameObject.GetComponent <ILaserableObject>();
            if (laserableObject != null)
            {
                Debug.Log("Hit laserable object: " + hit.transform.name);
                laserableObject.LaserHit(this, hit);
            }
            else
            {
                Debug.Log("Hit non-laserable object: " + hit.transform.name);
            }
        }
        else
        {
            Laser.laser.localScale = new Vector3(1, 1, 100);
        }
    }