Beispiel #1
0
    public void ShootRay()
    {
        // transform.forward 잘쓰면될듯
        List <Vector3> points        = new List <Vector3>();
        Vector3        lastPoint     = shootPoint.position;
        Vector3        lastDirection = transform.forward;
        int            maxSize       = 10; // MapManager.inst.currentMap.maxMapSize
        RaycastHit     hit;
        bool           isHit;

        points.Add(lastPoint);
        do
        {
            isHit = Physics.Raycast(lastPoint, lastDirection, out hit, maxSize);
            if (isHit)
            {
                lastPoint   = hit.transform.position;
                lastPoint.y = rayHeight;
                points.Add(lastPoint);

                if (hit.transform.GetComponent <Wall>() is Wall w)
                {
                    if (w.type == WallType.Mirror)
                    {
                        if (w.dir)
                        {
                            lastDirection.z *= -1;
                        }
                        else
                        {
                            lastDirection.x *= -1;
                        }
                    }
                    else if (w.type == WallType.Normal)
                    {
                        isHit = false; // end ray
                    }
                }
                else if (hit.transform.GetComponent <LightGetter>() is LightGetter lg)
                {
                    lg.SetReceived(true);
                    receivedGetter = lg;

                    isHit = false; // end ray
                }
            }
            else
            {
                points.Add(lastPoint + lastDirection * maxSize);
            }
        } while (isHit && maxSize > Mathf.Max(lastPoint.x, lastPoint.z));
        rayRenderer.positionCount = points.Count;
        rayRenderer.SetPositions(points.ToArray());
    }
Beispiel #2
0
 public void SetRayActive(bool isActive)
 {
     if (isRayActive != isActive)
     {
         isRayActive = isActive;
         if (isActive)
         { // turn on ray
             rayRenderer.enabled = true;
             ShootRay();
         }
         else
         { // turn off ray
             rayRenderer.enabled = false;
             receivedGetter?.SetReceived(false);
             receivedGetter = null;
         }
     }
 }