Example #1
0
    public void Update()
    {
        #region Place tower health slider
        Vector2 viewportPosition_start = this.Camera.WorldToScreenPoint(this.TowerLocationStart.position);
        Vector2 viewportPosition_end   = this.Camera.WorldToScreenPoint(this.TowerLocationEnd.position);

        RectTransform rt = this.TowerHealthSlider.GetComponent <RectTransform>();
        rt.sizeDelta          = new Vector2(viewportPosition_end.x - viewportPosition_start.x, rt.sizeDelta.y);
        rt.anchoredPosition3D = new Vector3(viewportPosition_start.x + rt.sizeDelta.x / 2, viewportPosition_start.y, 0);
        #endregion

        if (lightningChargeMeter.Full() && !this.died)
        {
            bool executeAll = false;

            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, 100.0f))
                {
                    if (hit.transform.name.Contains("Cube"))
                    {
                        executeAll = true;
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Space) || executeAll)
            {
                lightningChargeMeter.Deplete();
                BoatController[] boats = GameObject.FindObjectsOfType <BoatController>();

                foreach (BoatController boat in boats)
                {
                    if (!boat.Sinking)
                    {
                        GameObject go = GameObject.Instantiate(LightningPrefab);
                        Lightning  l  = go.GetComponent <Lightning>();
                        var        p  = boat.transform.position;
                        p.x            -= 4; // not sure why needed
                        p.y            -= 1; // not sure why needed
                        l.EndPosition   = p;
                        p.y            += 40;
                        l.StartPosition = p;

                        boat.Smoke();
                        boat.Sink(false);

                        this.Camera.clearFlags = CameraClearFlags.Color;
                        StartCoroutine(RestoreSkyBox());
                    }
                }
            }
        }
    }