예제 #1
0
    IEnumerator FireLaser(LineRenderer lineCR, bool forRit)
    {
        lineCR.enabled = true;
        while (transmitOutWatts > 0.0f && (start || isHit))
        {
            Ray ray;
            if (forRit)
            {
                ray = new Ray(transform.position, transform.forward);
            }
            else
            {
                ray = new Ray(transform.position, transform.right);
            }

            RaycastHit hit;

            lineCR.SetPosition(0, ray.origin);
            if (Physics.Raycast(ray, out hit, 100))
            {
                lineCR.SetPosition(1, hit.point);
                if (hit.collider)
                {
                    if (laserHitOne != null)
                    {
                        if (laserHitTwo != null)
                        {
                            laserHitTwo = laserHitTwo.DisableLaser(false);
                        }
                        laserHitTwo = laserHitOne;
                        laserHitOne = laserHitOne.DisableLaser(laserOneHitOne);
                    }
                    //Only care if laser is split
                    if (laserType == LaserType.split && laserHitTwo != null)
                    {
                        laserHitTwo.WasHit(false, transmitOutWatts);
                    }
                    laserHitOne = hit.collider.GetComponent <LaserController>();

                    bool which = true;
                    if (transmitInWattsOne == 0.0f && transmitInWattsTwo > 0.0f)
                    {
                        which = false;
                    }
                    laserOneHitOne = which;
                    laserHitOne.WasHit(which, transmitOutWatts);
                }
            }
            else
            {
                if (laserHitOne != null)
                {
                    laserHitTwo = laserHitOne;
                    laserHitOne = laserHitOne.DisableLaser(laserOneHitOne);
                }
                lineCR.SetPosition(1, ray.GetPoint(100));
            }
            yield return(null);
        }

        if (laserHitOne != null)
        {
            laserHitOne = laserHitOne.DisableLaser(laserOneHitOne);
        }
        if (laserHitTwo != null)
        {
            laserHitTwo = laserHitTwo.DisableLaser(false);
        }
        lineCR.enabled = false;
    }