void selectObject() { if (curControlled != null) { curControlled.GetComponent <Troop>().controlled = false; curControlled.GetComponent <Troop>().cameraFocusOnExit(); curControlled = null; } Ray interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit interactionInfo; if (Physics.Raycast(interactionRay, out interactionInfo, Mathf.Infinity)) { if (interactedObject != null && interactedObject.GetComponent <BattleInteractable>() != null) { interactedObject.GetComponent <BattleInteractable>().cameraFocusOnExit(); } interactedObject = interactionInfo.collider.gameObject.transform.parent.gameObject; if (interactedObject.tag == "Troop") { interactedObject.GetComponent <Troop>().cameraFocusOn(); if (interactedObject.GetComponent <Troop>().person.faction == Faction.mercenary && BattleCentralControl.playerTurn) { curControlled = interactedObject; skillMode = TroopSkill.walk; } } else if (interactedObject.tag == "Grid") { interactedObject.GetComponent <GridObject>().cameraFocusOn(); } else { Debug.Log(interactedObject.name); } } }
void inputKeysActions() { if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { if (BattleCentralControl.playerTurn && curControlled != null && skillMode != TroopSkill.walk) { curControlled.GetComponent <Troop>().doSkill(curControlled.GetComponent <Troop>().indicatedGrid(), skillMode); if (Input.GetMouseButtonDown(0)) { skillMode = TroopSkill.walk; } } else { if (!inAction) { selectObject(); } } } if (Input.GetMouseButtonDown(1) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { if (curControlled != null && BattleCentralControl.playerTurn) { if (skillMode == TroopSkill.walk) { if (curControlled.GetComponent <Troop>().reachedDestination) { curControlled.GetComponent <Troop>().cameraFocusOn(); walkToObj(); } } else if (skillMode == TroopSkill.none && Input.GetMouseButtonDown(1)) { skillMode = TroopSkill.walk; } else { skillMode = TroopSkill.none; curControlled.GetComponent <Troop>().hideIndicators(); } } } if (Input.GetKeyDown(KeyCode.Tab)) { if (BattleCentralControl.playerTurn) { if (curControlled != null) { curControlled.GetComponent <Troop>().cameraFocusOnExit(); curControlled = getNextPersonOnField(curControlled.GetComponent <Troop>().person).troop.gameObject; curControlled.GetComponent <Troop>().cameraFocusOn(); } else { foreach (KeyValuePair <Person, GameObject> pair in BattleCentralControl.playerTroopOnField) { BattleInteraction.curControlled = pair.Value; BattleInteraction.curControlled.GetComponent <Troop>().cameraFocusOn(); break; } } } } if (Input.GetKeyDown(KeyCode.Escape)) { if (skillMode == TroopSkill.walk) { SceneManager.LoadScene("MenuScene"); } else { skillMode = TroopSkill.walk; } } }
// Use this for initialization void Start() { skillMode = TroopSkill.walk; inAction = false; }