//	void ClickToDiscover(){
    //		Vector3 m = Camera.main.ScreenToWorldPoint (Input.mousePosition);
    //		Vector3 mouseRounded = new Vector3 (Mathf.Round (m.x), Mathf.Round (m.y), 0.0f);
    //
    //
    //		resourceGrid.DiscoverTile ((int)mouseRounded.x,(int) mouseRounded.y);
    //
    //	}
    //	void LateUpdate(){
    //		transform.position = new Vector3(Mathf.Lerp(transform.position.x, resourceGrid.TileCoordToWorldCoord (posX, posY).x, movementSpeed * Time.time),
    //		                                 Mathf.Lerp(transform.position.x, resourceGrid.TileCoordToWorldCoord (posX, posY).y, movementSpeed * Time.time) , 0);
    //	}


    public void MoveToNextTile()
    {
        if (currentPath == null)
        {
            return;
        }
        // Remove the old first node from the path
        currentPath.RemoveAt(0);

        if (resourceGrid.UnitCanEnterTile(currentPath [0].x, currentPath [0].y) == false)
        {
            Debug.Log(gameObject.name + "'s path is BLOCKED!");
            moving = false;
            anim.SetTrigger("idle");
            anim.ResetTrigger("movingRight");
            anim.ResetTrigger("movingLeft");
            currentPath = null;
            return;
        }


        //		// Check if the next tile is a UNWAKABLE tile, if it is: DISCOVER TILE & clear path
        //		if (resourceGrid.UnitCanEnterTile (currentPath [0].x, currentPath [0].y) == true) {
        //			resourceGrid.DiscoverTile (currentPath [0].x, currentPath [0].y, false);
        //		} else {
        //			resourceGrid.DiscoverTile(currentPath[0].x, currentPath[0].y, false);
        //			// check again, now that it has been discovered
        //			if (resourceGrid.UnitCanEnterTile (currentPath [0].x, currentPath [0].y) == false){
        //				currentPath = null;
        //				return;
        //			}
        //		}
        // Move to the next Node position in path
        posX = currentPath [0].x;
        posY = currentPath [0].y;
        // This MOVEMENT will just TELEPORT the unit to the next position in case we didn't make it
        //		transform.position = resourceGrid.TileCoordToWorldCoord (currentPath [0].x, currentPath [0].y);
        //		transform.position = resourceGrid.TileCoordToWorldCoord (posX, posY);



        // We are on the tile that is our DESTINATION,
        // CLEAR PATH
        if (currentPath.Count == 1)
        {
            currentPath = null;
            // This unit has finished walking its path so it no longer has to be selected
            isSelected = false;
        }
    }
Пример #2
0
    public void MoveToNextTile()
    {
        if (currentPath == null)
        {
            return;
        }
        // Remove the old first node from the path
        currentPath.RemoveAt(0);

        // Check if the next tile is a UNWAKABLE tile OR if it is clear path
        if (resourceGrid.UnitCanEnterTile(currentPath [1].x, currentPath [1].y) == false)
        {
            moving = false;
            Debug.Log("Path is blocked! at x" + currentPath [1].x + ", y" + currentPath [1].y);
            if (CheckForTileAttack(currentPath [1].x, currentPath [1].y))
            {
                Debug.Log("Attacking Tile!");
                // here I would tell the Attack script to start its attack on the tile
                // But if it's the Destination tile, not just any tile, then it needs to do a special attack
                if (currentPath[1].x == destination.x && currentPath[1].y == destination.y)
                {
                    // we are at the destination! Do special!
                    enemyAttkHandler.SpecialAttack(currentPath[1].x, currentPath[1].y);
                }
                else
                {
                    // it's a tile but NOT the destination, so just do normal attack
                    targetPosX = currentPath [1].x;
                    targetPosY = currentPath [1].y;
                    enemyAttkHandler.targetTilePosX = currentPath [1].x;
                    enemyAttkHandler.targetTilePosY = currentPath [1].y;
                    enemyAttkHandler.resourceGrid   = resourceGrid;
                    enemyAttkHandler.canAttackTile  = true;
                    isAttacking = true;
                }
            }
        }
        else
        {
            if (isAttacking)              // at this point if this is true it means this unit is engaging a Player Unit
            {
                currentPath = null;
                moving      = false;
                return;
            }

            // this check if for KAMIKAZE UNITS ONLY
            if (isKamikaze)
            {
                // if the next tile on the Path is the destination
                if (currentPath[1].x == destination.x && currentPath[1].y == destination.y)
                {
                    // reached the destination, do Special Attack!
                    enemyAttkHandler.SpecialAttack(currentPath[1].x, currentPath[1].y);
                }
            }
        }
        // Move to the next Node position in path
        posX = currentPath [1].x;
        posY = currentPath [1].y;

        // We are on the tile that is our DESTINATION,
        // CLEAR PATH
        if (currentPath.Count == 1)
        {
            currentPath = null;
        }
    }