Пример #1
0
 void checkMirrorSelection()
 {
     if (playerInteraction.selectedMirror != null) //If there is a mirror selected
     {
         if (selected == null)
         {
             playerMovement.enabled = false;
             selected      = playerInteraction.selectedMirror;
             currentMirror = selected.GetComponent <MirrorRotation>();
             mirrorType    = selected.GetComponent <Mirror>(); //Testing
         }
     }
     else if (!playerMovement.enabled)
     {
         if (selected != null)
         {
             playerMovement.enabled = true;
             selected      = null;
             currentMirror = null;
             mirrorType    = null; //Testing
         }
     }
 }
Пример #2
0
    private void DrawLaser()                                 //Instantiate various LineRenderers
    {
        bool loopActive = true;                              //Is the reflecting loop active?

        Vector3 laserDirection = transform.forward;          //direction of the next laser

        Vector3 lastLaserPosition = transform.localPosition; //origin of the next laser

        Color nextColor    = Color.white;                    //color of the next laser
        Color currentColor = Color.white;                    //color of the current laser

        RaycastHit hit;

        while (loopActive)
        {
            if (Physics.Raycast(lastLaserPosition, laserDirection, out hit, laserDistance, ignoreLayers))
            {
                currentColor = nextColor;
                createNewLaser(hit.point, lastLaserPosition, laserDirection, nextColor);
                nextColor = hit.transform.gameObject.GetComponent <Renderer>().material.color;

                if (hit.transform.gameObject.CompareTag(bounceTag))
                {
                    currentMirror = hit.transform.gameObject.GetComponent <MirrorRotation>();

                    if (currentMirror != null && currentMirror.isFacingMirror(laserDistance, ignoreLayers)) //Two lasers face each other
                    {
                        mLineRenderer.startColor = currentColor;
                        mLineRenderer.endColor   = nextColor;
                        loopActive = false;
                    }

                    lastLaserPosition = hit.point;
                    laserDirection    = Vector3.Reflect(laserDirection, hit.normal);
                    nextColor         = mixColors(currentColor, nextColor);
                }
                else if (hit.transform.gameObject.CompareTag(doorHandlerTag)) //Check if puzzle is solved
                {
                    checkPuzzleSolved(hit, currentColor);
                    loopActive = false;
                }
                else
                {
                    mLineRenderer.SetPosition(1, hit.point);
                    lastLaserPosition = transform.position;
                    if (doorHandlerScript != null)
                    {
                        doorHandlerScript.activateAnimation = false;
                    }

                    loopActive = false;
                }
            }
            else
            {
                createNewLaser(lastLaserPosition + laserDirection.normalized * laserDistance, lastLaserPosition, laserDirection, nextColor);
                if (doorHandlerScript != null)
                {
                    doorHandlerScript.activateAnimation = false;
                }

                loopActive = false;
            }
        }
    }
Пример #3
0
 // Use this for initialization
 void Start()
 {
     rot    = GetComponentInChildren <MirrorRotation>();
     moving = false;
 }