Exemplo n.º 1
0
        /// <summary>
        ///   Gets called upon the event <c>OnHitSwitch</c>.
        /// </summary>
        /// <param name="reference">
        ///   Position of the clicked switch in grid coordinates.
        /// </param>
        /// <param name="grid">
        ///   The grid we use for reference.
        /// </param>
        private void OnHitSwitch(Vector3 reference, RectGrid grid)
        {
            // Don't do anything if this light doesn't belong to the grid we
            // use.
            if (grid != _grid)
            {
                return;
            }

            // Check if this light is adjacent to the switch; this is an
            // extenion method that always picks the method that belongs to the
            // specific grid type. The implementation is in another file.
            var isAdjacent = grid.AreAdjacent(transform.position, reference);

            if (isAdjacent)
            {
                _isOn = !_isOn;
                SwitchLights();
            }
        }