Пример #1
0
        // Awake is called before Start()
        void Awake()
        {
            var grid = GetComponent <RectGrid>();
            var para = GetComponent <Parallelepiped>();

            ForbiddenTiles.Initialize(grid, para);
        }
Пример #2
0
        /// <summary>
        ///   Pick the next goal based on user input. The input if filtered
        ///   through a number for criteria.
        /// </summary>
        private void PickNext()
        {
            Vector3 direction;              // Direction to move in (grid-coordinates)

            var h = Input.GetAxisRaw("Horizontal");
            var v = Input.GetAxisRaw("Vertical");

            if (h > 0)
            {
                direction = Vector3.right;
            }
            else if (h < 0)
            {
                direction = Vector3.left;
            }
            else if (v > 0)
            {
                direction = Vector3.up;
            }
            else if (v < 0)
            {
                direction = Vector3.down;
            }
            else
            {
                return;
            }

            // We will be operating in grid space, so convert the position
            _goal = _grid.WorldToGrid(transform.position) + direction;

            // Check that the target is still inside the rendered region of the
            // grid.
            for (var i = 0; i < 2; ++i)
            {
                var beyondLower = _goal[i] < _renderer.From[i];
                var beyondUpper = _goal[i] > _renderer.To[i];

                if (beyondLower || beyondUpper)
                {
                    Debug.Log("I can't swim.");
                    return;
                }
            }

            // Check for walls
            if (!ForbiddenTiles.CheckTile(_goal))
            {
                Debug.Log("Ouch!");
                return;
            }

            _goal     = _grid.GridToWorld(_goal);
            _isMoving = true;
        }
Пример #3
0
 // Start() is called after Awake(), this ensures that the matrix has
 // already been built.
 void Start()
 {
     // Set the entry that corresponds to the obstacle's position as
     // false.
     ForbiddenTiles.SetTile(transform.position, false);
 }