Пример #1
0
        public void Advance()
        {
            if (canAdvance)
            {
                if (Raycast.CastRay(start, direction, out RaycastInfo info, Laser.MaxDistance))
                {
                    BaseElement element = info.element;

                    Laser.HandleRefractiveIndices(lastCollided, element, wavelength, out float initial, out float final);
                    lastCollided = element;

                    start = info.point;
                    collisionPoints.Add(start);

                    if (element.BlocksRays)
                    {
                        canAdvance = false;
                        return;
                    }

                    float angle = Vector2.SignedAngle(info.normal, -direction);

                    float scale = 1f;
                    if (element is Refractor)
                    {
                        scale = 1f + (1f - (float)((wavelength - 400f) / (750f - 400f))) * 0.1f;
                    }

                    float outAngle = element.GetAngle(angle, initial, final) * scale;

                    direction = Vector2.Transform(info.normal, Quaternion.FromAxisAngle(Vector3.UnitZ, outAngle)) * (info.element is Mirror ? 1 : -1);
                    start    += direction * 0.01f;
                }
                else
                {
                    canAdvance = false;
                    collisionPoints.Add(start + direction * Laser.MaxDistance);
                }
            }
Пример #2
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (canBePurchased && inPurchase)
     {
         Vector3    screenPoint = Camera.main.WorldToViewportPoint(mousePosition);
         bool       onScreen    = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
         Collider2D collider    = raycast.CastRay(mousePosition, Vector2.zero);
         if (collider != null && onScreen)
         {
             GameObject tile = collider.gameObject;
             if (tile.tag == "empty")
             {
                 gameManager.GetComponent <gameManager>().playerEnergy -= turretPrice;
                 Instantiate(turret, tile.transform.position, Quaternion.identity);
                 Destroy(tile);
             }
         }
         Destroy(turretImage);
         GetComponent <Image>().enabled = true;
         inPurchase = false;
     }
 }