public void EnemyTurn()//all the steps enemy will do in enenmy turn
    {
        if (NextTurn)
        {
            if (CheckInRange)
            {
                foreach (Vector3Int vector in EnemySight)// if player is in sight area, player is detected
                {
                    if (tilemap.WorldToCell(Player.position) == vector)
                    {
                        PlayerIsDetected = true;
                        break;
                    }
                    else
                    {
                        PlayerIsDetected = false;
                    }
                }
                CheckInRange = false;
            }

            if (PlayerIsDetected)
            {
                if (!OnlyOnce)
                {
                    EnemyToPlayer = pathfinding.FinDAPath(tilemap.CellToWorld(EnemyMapPosition), Player.position);
                    for (int i = 0; i < EnemyToPlayer.Count; i++)
                    {
                        for (int x = 0; x < EnemyMoveRange.Count; x++)
                        {
                            if (new Vector3Int(EnemyToPlayer[i].position[0], EnemyToPlayer[i].position[1], EnemyToPlayer[i].position[2]) == EnemyMoveRange[x])
                            {
                                Tem.Add(EnemyMoveRange[x]);
                            }
                        }
                    }

                    OnlyOnce = true;
                }
                EnemyMove();//enemy move towards player
            }
            else
            {
                EnemyWonder();
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (PathFinished)//check if in player turn
        {
            if (Input.GetMouseButtonDown(0))
            {
                foreach (Vector3Int vector in PositionsInRange)//check if the click is in movement range
                {
                    if (tilemap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)) == vector)
                    {
                        ClickInRange = true;
                        break;
                    }
                    else
                    {
                        ClickInRange = false;
                    }
                }
                if (ClickInRange)
                {
                    target.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Path            = pathfinding.FinDAPath(transform.position, target.position);
                }
            }
        }

        //if(Physics2D.Linecast(transform.position, target.position,lineMask))
        //{
        //    Debug.Log("collider exists");
        //}
        //else
        //{
        //    Debug.Log("no collider");
        //}


        if (Input.GetKeyDown("space"))
        {
            Pause = true;
        }

        DisPlayMovementRange();
        WalkOnPath();
    }