Exemple #1
0
    public void MoveNextTile()
    {
        remainingMovement = MovementSpeed;
//		Debug.Log(remainingMovement);
//		CalculateDistancesToPlayers();
//		GameObject Unit = GameObject.Find ("UnitOne");
        selectTargetting();
//		CalculateDistancesToPlayers();
        GameObject        Player = GameObject.Find(selectedPlayer);
        PlayableCharacter player = Player.GetComponent <PlayableCharacter> ();

        map.GeneratePathToEnemy(player.PlayerClass.TileX, player.PlayerClass.TileY);

        while (remainingMovement > 0)
        {
            currentTile = ("Hex_" + TileX + "_" + TileY);
            GameObject.Find(currentTile).GetComponent <ClickableTile> ().IsNotWalkable();

//			tile.IsNotWalkable();
            int tileXHolder = TileX;
            int tileYHolder = TileY;
            CalculateDistance();

            if ((currentPath == null || distance <= AttackRange) && Blinded == false)
            {
//				Debug.Log(remainingMovement);
                if (remainingMovement >= 1)
                {
                    Attack();
                }
                return;
            }
            if ((currentPath == null || distance <= AttackRange) && Blinded == true)
            {
                return;
            }
            // Get cost from current tile to next tile
            remainingMovement -= map.CostToEnterTile(currentPath[0].x, currentPath[0].y, currentPath[1].x, currentPath[1].y);

            // Move us to the next tile in the sequence
            TileX = currentPath[1].x;
            TileY = currentPath[1].y;

            transform.position = map.TileCoordToWorldCoord(TileX, TileY);               // Update our unity world position

            // Remove the old "current" tile
            currentPath.RemoveAt(0);
//			Debug.Log(this.name + " " + currentPath.Count);
            if (currentPath.Count == 1)
            {
                // We only have one tile left in the path, and that tile MUST be our ultimate
                // destination -- and we are standing on it!
                // So let's just clear our pathfinding info.
                currentPath = null;
            }
            currentTile = ("Hex_" + tileXHolder + "_" + tileYHolder);
            ClickableTile clickableTile = GameObject.Find(currentTile).GetComponent <ClickableTile> ();
            clickableTile.IsWalkable();
            currentTile   = ("Hex_" + TileX + "_" + TileY);
            clickableTile = GameObject.Find(currentTile).GetComponent <ClickableTile> ();
            clickableTile.IsNotWalkable();

            if (clickableTile.trapped)
            {
                clickableTile.trapped = false;
                GameObject Trap = GameObject.Find("_Scripts");
                Trap       trap = Trap.GetComponent <Trap> ();
                trap.TrapActivate();
            }
        }
    }