/// Update is called once per frame void Update() { if (_isDragged) { //Create a ray from the Mouse click position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //hit distance float enter = 100.0f; if (map.m_Plane.Raycast(ray, out enter)) { //Get the point that is clicked Vector3 hitPoint = ray.GetPoint(enter); //new character position Vector3 p = new Vector3(hitPoint.x, 1.0f, hitPoint.z); //move champion this.transform.position = Vector3.Lerp(this.transform.position, p, 0.1f); } } else { if (gamePlayController.currentGameStage == GameStage.Preparation) { //calc distance float distance = Vector3.Distance(gridTargetPosition, this.transform.position); if (distance > 0.25f) { this.transform.position = Vector3.Lerp(this.transform.position, gridTargetPosition, 0.1f); } else { this.transform.position = gridTargetPosition; } } } if (isInCombat && isStuned == false) { if (target == null) { combatTimer += Time.deltaTime; if (combatTimer > 0.5f) { combatTimer = 0; TryAttackNewTarget(); } } //combat if (target != null) { //rotate towards target this.transform.LookAt(target.transform, Vector3.up); if (target.GetComponent <ChampionController>().isDead == true) //target champion is alive { //remove target if targetchampion is dead target = null; navMeshAgent.isStopped = true; } else { if (isAttacking == false) { //calculate distance float distance = Vector3.Distance(this.transform.position, target.transform.position); //if we are close enough to attack if (distance < champion.attackRange) { DoAttack(); } else { navMeshAgent.destination = target.transform.position; } } } } } //check for stuned effect if (isStuned) { stunTimer -= Time.deltaTime; if (stunTimer < 0) { isStuned = false; championAnimation.IsAnimated(true); if (target != null) { //set pathfinder target navMeshAgent.destination = target.transform.position; navMeshAgent.isStopped = false; } } } }