Beispiel #1
0
    // Lấy vị trí ngẫu nhiên trong khu vực
    public Vector2 GetRandomPositionInArea(SAreaMoveTo area)
    {
        float x = Random.Range(area.center.transform.position.x - area.width / 2, area.center.transform.position.x + area.width / 2);
        float y = Random.Range(area.center.transform.position.y - area.height / 2, area.center.transform.position.y + area.height / 2);

        return(new Vector2(x, y));
    }
Beispiel #2
0
 // Kiểm tra vị trí đó có nằm bên trong khu vực đó hay không
 bool IsInArea(Vector3 pos, SAreaMoveTo area)
 {
     if (pos.x < area.center.transform.position.x - area.width / 2 ||
         pos.x > area.center.transform.position.x + area.width / 2 ||
         pos.y < area.center.transform.position.y - area.height / 2 ||
         pos.y < area.center.transform.position.y - area.height / 2)
     {
         return(false);
     }
     return(true);
 }
Beispiel #3
0
    public GameObject debugEndPoint;   // Điểm kết thúc

    void Start()
    {
        nodeArrays = new Node[rows, columns];
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
            {
                nodeArrays[i, j] = new Node(j, i, false);

                nodeArrays[i, j].worldPos = new Vector2(this.transform.position.x + j * alignment, this.transform.position.y - i * alignment);

                // Node nào dính vào vật cản thì coi như node đó là tường
                if (Physics2D.OverlapCircle(nodeArrays[i, j].worldPos, nodeRadius, ObstacleMask) != null)
                {
                    nodeArrays[i, j].IsWall = true;
                }
            }
        }

        // Lưu trữ riêng khu vực giữa 2 team nơi cả 2 team đều đi tới
        centerArea = listArea[centerAreaIndex];
    }