Ejemplo n.º 1
0
        protected override void Awake()
        {
            base.Awake();

            agent                 = new NavigationAgent();
            agent.width           = agent.height = 1;
            agent.range           = 30;
            agent.penaltyModifier = 1;

            mainCamera = Camera.main;
            boundSize  = new Vector3();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if a Given tile in the Grid is Walkable by an Agent
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="tile"></param>
        /// <param name="agentWidth"></param>
        /// <param name="agentHeight"></param>
        /// <returns></returns>
        public static bool IsTileWalkableByAgent(this Tilemap grid, Tile tile, NavigationAgent agent)
        {
            int xLimit = Mathf.Clamp(tile.x + agent.width, 0, grid.Columns);
            int yLimit = Mathf.Clamp(tile.y - agent.height, 0, grid.Rows);

            for (int y = tile.y; y > yLimit; y--)
            {
                for (int x = tile.x; x < xLimit; x++)
                {
                    if (!grid.Tiles[x, y].walkable)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }