Example #1
0
    void BattleScreen()
    {
        if (Input.GetButtonDown("Escape"))
        {
            Toggle();
        }
        if (Input.GetButtonDown("Switch"))
        {
            StatToggle();
        }

        //Camera Controls
        if (Input.GetButton("Horizontal"))
        {
            gameObject.transform.Translate(new Vector2(Input.GetAxis("Horizontal"), 0));
        }
        if (Input.GetButton("Vertical"))
        {
            gameObject.transform.Translate(new Vector2(0, Input.GetAxis("Vertical")));
        }

        if (Input.GetButtonDown("Select"))
        {
            if (FreezeClicks)
            {
                //Skips Playing Animation for Battles and Moving
                skipToggle();
                skipToggle();
                return;
            }

            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down * 10, out hit, 10))
            {
                if (hit.collider != null)
                {
                    if (EventSystem.current.IsPointerOverGameObject())
                    {
                    }
                    else if (hit.collider.GetComponent <UnitActions>() != null)
                    {
                        if (!hit.collider.GetComponent <UnitActions>().ActionAvailable&& hit.collider.tag == LevelManager.DM.ActiveFactionReturn())
                        {
                            return; //Stops check if the unit is able to be interacted with
                        }
                        if (hit.collider.gameObject != HeldObject)
                        {
                            //Checks if the Unit is is checking for viable targets
                            if (HeldObject != null)
                            {
                                print("Unit is searching target = " + HeldObject.GetComponent <UnitActions>().AttackChecking);
                            }
                            if (HeldObject != null && HeldObject.GetComponent <UnitActions>().AttackChecking)
                            {
                                print("Unit is checking for Valid Targets");
                                UnitActions unitActions = HeldObject.GetComponent <UnitActions>();
                                if (hit.collider.tag == HeldObject.tag)
                                {
                                    return;//Ends function check
                                }
                                else if (hit.collider.tag != HeldObject.tag)
                                {
                                    //Checks if selected unit is within the target space
                                    if (unitActions.ValidAttack(hit.collider.gameObject))
                                    {
                                        HeldObject.GetComponent <UnitActions>().AttackPhase(hit.collider.gameObject);
                                        Cancel();
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                if (HeldObject != null)
                                {
                                    GameManager.GManager.HeldObject.GetComponent <UnitActions>().WipeSelect();
                                }
                                if (!UIManager.ActionsActive)
                                {
                                    ActToggle();
                                }
                                HeldObject = hit.collider.gameObject;
                                HeldObject.GetComponent <UnitActions>().isSelected = true;
                                return;
                            }
                        }
                        else if (hit.collider.gameObject == HeldObject)
                        {
                            if (HeldObject.GetComponent <UnitActions>().ActionsMove)
                            {
                                CallAction_Move();
                            }
                            else if (HeldObject.GetComponent <UnitActions>().ActionAvailable)
                            {
                                CallAction_Attack();
                            }
                        }
                    }
                    else if (hit.collider.GetComponent <TerrainProperty>() != null)
                    {
                        TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>();
                        if (terrain.isValid && !terrain.isHostile)
                        {
                            if (HeldObject != null)
                            {
                                //Move Agent
                                terrain.isTarget = true;

                                HeldObject.GetComponent <UnitActions>().MovementPhase(hit.collider.gameObject);
                                GameManager.GManager.HeldObject.GetComponent <UnitActions>().WipeSelect();
                                GameManager.GManager.HeldObject.GetComponent <UnitActions>().isSelected = true;
                                //Cancel();
                                //HeldObject = null;
                            }
                        }
                        else if (terrain.isValid && terrain.isHostile)
                        {
                            HeldObject.GetComponent <UnitActions>().AttackPhase(hit.collider.gameObject);
                        }
                    }
                    else
                    {
                        Debug.Log("Unit Not Found");
                    }
                }
                else
                {
                    Debug.Log("Nothing Found");
                }
            }
        }

        if (Input.GetButtonDown("Cancel"))
        {
            Cancel();
        }
        if (Input.GetButtonDown("Action1"))
        {
            CallAction_Move();
        }
        if (Input.GetButtonDown("Action2"))
        {
            CallAction_Attack();
        }
        if (Input.GetButtonDown("Action3"))
        {
            CallAction_Sync();
        }
        if (Input.GetButtonDown("Action4"))
        {
            CallAction_Defend();
        }
        if (Input.GetButtonDown("Action5"))
        {
            CallAction_Wait();
        }
    }