Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                unitCtrl.targetTile = hit.transform;
                targetTile          = hit.transform;

                //State Map
                if (state == ControlState.Map && !camManager.camMoving)
                {
                    if (oldRender != null)
                    {
                        oldRender.color = new Color(255, 255, 255);
                    }

                    //Get Tile Selected
                    SpriteRenderer sprLine = hit.transform.GetChild(0).GetComponent <SpriteRenderer>();
                    oldRender     = sprLine;
                    sprLine.color = new Color(0, 255, 0);

                    //Move Camera
                    StartCoroutine(camManager.LerpCam(cam.transform.position, camManager.camPosStatic(targetTile.position)));

                    //Get Tile Info
                    TileData tileInfo = hit.transform.GetComponent <TileData>();

                    //Get Unit Info
                    if (tileInfo.haveUnit)
                    {
                        unitUIInfo(tileInfo.UnitOn.GetComponent <UnitInfo>(), null, true);
                    }
                    else
                    {
                        unitUIInfo(null, null, false);
                    }

                    //UI Manage
                    tileInfoPanel.SetActive(true);
                    tileInfoText.text = GetThing.getTileType(targetTile);
                }
                else if (state == ControlState.Move)
                {
                    if (unitCtrl.targetTile.GetComponentInParent <TileData>().canMoveTo)
                    {
                        //print(targetTile.GetComponentInParent<TileData>().canMoveTo);
                        TileData data = unitOnControl.GetComponent <UnitInfo>().tileOn.GetComponent <TileData>();
                        data.haveUnit    = false;
                        data.canMoveTo   = true;
                        unitCtrl.allPath = PathManager.DoMovePath(unitOnControl.GetComponent <UnitInfo>().tileOn, targetTile, unitOnControl, this.GetComponent <PlayerController>());
                        unitCtrl.unit.GetComponent <UnitInfo>().isMoving = true;
                        PathManager.DoHideMovableTile();
                        controlPanel.SetActive(false);
                    }
                }
                else if (state == ControlState.Attack)
                {
                    if (targetTile.GetComponent <TileData>().UnitOn != null)
                    {
                        PathManager.DoHideMovableTile();
                        Transform unitTarget = targetTile.GetComponent <TileData>().UnitOn;
                        battle.DoBattle(unitOnControl, unitTarget);
                        turn.FinishAction();
                        controlPanel.SetActive(true);
                    }
                }
            }
        }
    }