Exemplo n.º 1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Assert(Camera.main != null, "Camera.main != null");
            Collider2D hit      = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
            CellInfo   cellInfo = hit != null?hit.gameObject.GetComponent <CellInfo>() : null;

            if (cellInfo != null)
            {
                Vector2Int pos = cellInfo.GetPos();
                map[pos.x, pos.y] = (map[pos.x, pos.y] + 1) % 2;                //修改铺设状态,每次点击都是状态取反
                cellInfo.UpdateState(map[pos.x, pos.y]);
            }
        }
    }