public void OnMainActionEquip(RaycastHit rayHit) { rayHit.transform.gameObject.SendMessage("OnTarget"); EquipService.OnTarget(rayHit.collider.gameObject); if (enemy_target != null) { enemy_target.SendMessage("TargetDisable"); enemy_target = null; } }
public void OnMainAciton() { if (this.in_action) { return; } this.in_action = true; //if (!this.character_control) return; if (this.state == State.Dead) { return; } //if (!character_control) return; //RaycastHit rayHit = new RaycastHit(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Debug.Log("PlayerController.OnMainAciton() : Input.mousePosition: " + Input.mousePosition); int layer_mask = (1 << LayerMask.NameToLayer("Default")) | (1 << LayerMask.NameToLayer("ItemEquip")) | (1 << LayerMask.NameToLayer("Enemy")); RaycastHit[] hits = Physics.RaycastAll(ray, 100, layer_mask); RaycastHit enemy_hit = new RaycastHit(); RaycastHit item_hit = new RaycastHit(); RaycastHit floor_hit = new RaycastHit(); foreach (var ray_hit in hits) { //Debug.Log("PlayerController.OnMainAciton() : ray_hit.point: " + ray_hit.point); if (ray_hit.collider == null) { continue; } if (ray_hit.transform.tag == "Enemy" && enemy_hit.collider == null) { enemy_hit = ray_hit; } else if (ray_hit.transform.tag == "ItemEquip" && item_hit.collider == null) { item_hit = ray_hit; } if (floor_hit.collider == null) { floor_hit = ray_hit; } } /* * if (5 < enemy_history.Count) { * var max = enemy_history.Count; * for (var count = 5; count < max; count += 1) { * var de = enemy_history.Dequeue(); * if (de != null) de.SendMessage("TargetDisable"); * } * } */ if (enemy_hit.collider != null) { if (enemy_target == null || enemy_target != enemy_hit.transform.gameObject) { //if (enemy_target != null) { enemy_target.SendMessage("TargetDisable"); } //enemy_history.Enqueue(enemy_hit.transform.gameObject); enemy_target = enemy_hit.transform.gameObject; foreach (var obj in GameObject.FindGameObjectsWithTag("Enemy")) { if (obj == enemy_target) { obj.SendMessage("OnTarget"); } else { obj.SendMessage("TargetDisable"); } } var ec = enemy_target.GetComponent <EnemyController>(); enemy_target_distance = ec.attack_distance; Debug.Log("enemy_target_distance : " + enemy_target_distance); enemy_target.SendMessage("OnTarget"); if (enemy_target_distance < Math.Abs(Vector3.Distance(enemy_target.transform.position, transform.position))) { nmAgent.ResetPath(); Observable.NextFrame().Subscribe(x => { if (nmAgent == null || !nmAgent.enabled) { return; } nmAgent.SetDestination(enemy_target.transform.position); }); AnimationChange("Idle"); } } //Debug.Log("new target : " + enemy_target.name); } else if (item_hit.collider != null) { item_hit.transform.gameObject.SendMessage("OnTarget"); EquipService.OnTarget(item_hit.collider.gameObject); if (enemy_target != null) { enemy_target.SendMessage("TargetDisable"); enemy_target = null; } } else { if (enemy_target != null) { enemy_target.SendMessage("TargetDisable"); enemy_target = null; } } if (enemy_hit.collider == null && floor_hit.collider != null) { nmAgent.ResetPath(); Observable.NextFrame().Subscribe(x => { nmAgent.SetDestination(floor_hit.point + na_destination_offset); }); //animator.radioBool("Idle"); //AnimationChange("Idle"); } AnimationChange("Dash"); this.in_action = false; /* * if (Physics.Raycast(ray, out rayHit, 100, layer_mask)) { * Debug.Log("rayHit.transform.gameObject.layer : " + rayHit.transform.gameObject.layer); * Debug.Log("rayHit.transform.tag : " + rayHit.transform.tag); * * if (rayHit.transform.tag == "Enemy") { * enemy_target = rayHit.transform.gameObject; * Debug.Log("new target : " + enemy_target.name); * enemy_target.SendMessage("OnTarget"); * } else * if (rayHit.transform.tag == "ItemEquip") { * rayHit.transform.gameObject.SendMessage("OnTarget"); * EquipService.OnTarget(rayHit.collider.gameObject); * * if (enemy_target != null) { * enemy_target.SendMessage("TargetDisable"); * enemy_target = null; * } * } else { * if (enemy_target != null) { * enemy_target.SendMessage("TargetDisable"); * enemy_target = null; * } * } * * if (rayHit.collider != null) { * //Debug.Log("rayHit.point: " + rayHit.point); * //nmAgent.destination = rayHit.point; * nmAgent.ResetPath(); * nmAgent.SetDestination(rayHit.point + na_destination_offset); * animator.SetBool("DoIdle", false); * * //Debug.Log("PlayerController::OnMainAciton() : rayHit.collider.gameObject.name : " + rayHit.collider.gameObject.name); * //Debug.Log("PlayerController::OnMainAciton() : rayHit.collider.gameObject.tag : " + rayHit.collider.gameObject.tag); * } * } */ }