// Update is called once per frame void Update() { if (attached_character.get_remaining_actions() > 0) { current_state.update_state(this); } }
//This function does most of the heavy lifting for interactions with the world private void check_attack() { bool attack_input = false; //If it's not our turn, or we've used all our actions, get out of here! if (!util_ref.g_manager.players_turn || attached_character.get_attack_remaining() <= 0) { return; } //Raycast to the point at z index 0 int attack = (int)Input.GetAxisRaw("Fire1"); Vector3 target = main_camera.ScreenToWorldPoint(Input.mousePosition); target = new Vector3(target.x, target.y, 0f); //If we got attack input, keep moving if (attack != 0) { attack_input = true; } //See if there's an interactable object at the point if (!has_attacked && attack_input) { //Raycast to check the point RaycastHit2D hit = Physics2D.Raycast(new Vector2(main_camera.ScreenToWorldPoint(Input.mousePosition).x, main_camera.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0f); //If we hit something... if(hit.transform != null) { //First check if we're even in range to care float dist = Vector2.Distance(transform.position, hit.transform.position); if(dist == 1) { //Check if there's an interactable component on the target Interactable interact = hit.transform.gameObject.GetComponent<Interactable>(); if (interact != null && attached_character.get_remaining_actions() > 0) { interact.force_interact(attached_character); has_attacked = true; if(attached_character.stats.get_stat_value("Move Actions") > 1) { attached_character.decrease_move(); } else { attached_character.decrease_attack(); } } } } } //If we've already attacked and don't have any input if (has_attacked && !attack_input) { //Mark that we can attack again has_attacked = false; } //If we haven't attacked and do have input if (!has_attacked && attack_input) { //Returns true if an attack was successful has_attacked = inv.do_attack(cur_skill, gameObject, target); if(has_attacked) { //manager.player_end_turn(); attached_character.decrease_attack(); //set_locked("Locked player to allow effect to play"); } } }